# Number.IsEven

## #

Here, we will dive deeper into the M code behind the Number.IsEven function. We will examine how the function works and how it can be used in various scenarios.

## The M Code Behind the Number.IsEven Function

The M code behind the Number.IsEven function is relatively straightforward. The function takes a single argument, which is the number to be checked. The code then checks whether the number is divisible by 2 without any remainder. If the number is divisible by 2, the function returns true. If not, it returns false.

Here is the M code for the Number.IsEven function:

Number.IsEven = (number) =>

number mod 2 = 0

``` As you can see, the code uses the mod operator to check whether the number is divisible by 2. The mod operator returns the remainder of a division operation. If the remainder is 0, the number is divisible by 2. Using the Number.IsEven Function The Number.IsEven function is commonly used in Power Query M to manipulate data based on whether a value is even or odd. For example, you can use the function to filter out odd numbers from a dataset, or to perform certain operations only on even numbers. Here is an example of using the Number.IsEven function to filter out odd numbers from a dataset: ```

let

Source = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10},

Filtered = List.Select(Source, each Number.IsEven(_) = true)

in

Filtered

``` In this example, the Source variable contains a list of numbers. The List.Select function is used to filter out odd numbers from the list, using the Number.IsEven function as the filter condition. The resulting list, Filtered, contains only even numbers: ```

{2, 4, 6, 8, 10}

``` The Number.IsEven function in Power Query M is a simple yet powerful tool for working with data. It allows you to easily check whether a number is even or odd, and use that information to manipulate data in various ways. By understanding the M code behind the function, you can gain a deeper understanding of how it works and how you can use it in your own projects. Power Query and M Training Courses by G Com Solutions (0800 998 9248) Power Query and M Intensive Training Course £1,050.00 – £26,550.00 Select optionsContinue Loading Done Power Query and M Introduction £395.00 – £9,750.00 Select optionsContinue Loading Done Power Query and M Intermediate £395.00 – £9,750.00 Select optionsContinue Loading Done Power Query and M Advanced £395.00 – £9,750.00 Select optionsContinue Loading Done Upcoming Courses Contact Us Subject Your Name (required) Company/Organisation Email (required) Telephone Training Course(s) Power BI Intensive TrainingPower BI introduction Power BI IntermediatePower BI AdvancedDAXPower Query MPower BI CertificationPower BI AdministrationPower PlatformPower AutomatePower AppsOTHER Your Message Upload Example Document(s) (Zip multiple files) ```
``` ```
``` ```
``` ```
``` ```
``` ```