# Number.Atan

## Overview of the Atan Function

The atan function returns the arctangent of a given number. In mathematical terms, this function calculates the angle whose tangent is equal to the given number. The result is returned in radians.

The syntax for the atan function in Power Query M is as follows:

Number.Atan(number as nullable number) as nullable number

``` This function takes a single argument, which is the number whose arctangent is to be calculated. The argument must be a nullable number, which means that it can be either a valid number or a null value. The M Code Behind Number.Atan The M code behind the Number.Atan function is relatively simple. The function takes the given number argument, converts it to a decimal value, and then passes it to the .NET Framework's Math.Atan method to calculate the arctangent. Here is the M code for the Number.Atan function: ```

let

Number.Atan = (number as nullable number) as nullable number =>

if number <> null then

Math.Atan(Number.From(number))

else

null

in

Number.Atan

``` Let's break down this code and see how it works. The let Statement The let statement is used to define a function in Power Query M. In this case, we are defining the Number.Atan function. The function takes a single argument, which is the number whose arctangent is to be calculated. The if Statement The if statement checks whether the given number argument is not null. If the argument is not null, the function proceeds to calculate the arctangent using the Math.Atan method. If the argument is null, the function returns a null value. The Math.Atan Method The Math.Atan method is a .NET Framework method that calculates the arctangent of a given number. The method takes a decimal value as its argument and returns a decimal value. In our case, we are passing the Number.From method as an argument to the Math.Atan method. Number.From is a Power Query M function that converts a given value to a decimal number. Examples of Using Number.Atan Let's look at some examples of using the Number.Atan function in Power Query M. Example 1: Calculating the Arctangent of a Number Suppose we have a table of values that we want to calculate the arctangent for. We can use the Number.Atan function to do this. Here is some sample code: ```

let

Source = #table({“Value”}, {{1}, {2}, {3}, {4}, {5}}),

in

``` In this code, we are creating a table with a single column called "Value". We then add a new column called "Arctan" using the Table.AddColumn function. The "Arctan" column is calculated using the Number.Atan function, which takes the value from the "Value" column as its argument. Example 2: Handling Null Values Suppose we have a table of values that includes null values. We want to calculate the arctangent for each non-null value and return null for the null values. Here is some sample code: ```

let

Source = #table({“Value”}, {{1}, {2}, null, {4}, {5}}),

``` In this code, we are creating a table with a single column called "Value". We then add a new column called "Arctan" using the Table.AddColumn function. The "Arctan" column is calculated using the Number.Atan function, which takes the value from the "Value" column as its argument. If the value is null, the Number.Atan function returns null. The Number.Atan function in Power Query M is a simple yet powerful function that allows us to calculate the arctangent of a given number. By understanding the M code behind this function, we can gain a deeper understanding of how it works and how we can use it in our Power Query 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) ```
``` ```
``` ```
``` ```
``` ```
``` ```