Number.Ln

D

T

The M Code Behind the Power Query M function Number.Ln

Understanding the Number.Ln Function

The Number.Ln function in Power Query is used to calculate the natural logarithm of a given number. The natural logarithm is the logarithm to the base e, where e is the mathematical constant approximately equal to 2.71828. The natural logarithm is commonly used in various mathematical and statistical calculations, particularly in data analysis.

The syntax for the Number.Ln function is as follows:


Number.Ln(number as nullable number) as nullable number


The function takes in a single argument, which is the number for which the natural logarithm is to be calculated. The argument can be a nullable number, which means it can be a number or null.

The M Code Behind the Number.Ln Function

The M code behind the Number.Ln function is relatively simple. Here's the code:


let

numberLn = (number as nullable number) =>

if number = null then null else Number.Log(number, 2.7182818284590452353602874713526624977572470936999595749669676277240766303535)

in

numberLn


Let's break down the code:

- The first line declares a variable called "numberLn", which is a function that takes in a single argument called "number". The "nullable number" data type is used to indicate that the argument can either be a number or null.

- The second line uses an "if...else" statement to check if the "number" argument is null. If it is, the function returns null. If it's not null, the function continues to the next line.

- The third line calls the "Number.Log" function, which calculates the logarithm of the "number" argument to the base e. The constant value for e is provided as a second argument to the function.

Using the Number.Ln Function in Power Query

Now that we understand the M code behind the Number.Ln function, let's see how we can use it in our data analysis projects.

Suppose we have a table with a column called "Values", which contains a list of numbers. We want to calculate the natural logarithm of each number in the column and add the results as a new column. Here's how we can do it:

1. Select the "Values" column in the query editor.

2. Go to the "Add Column" tab and select "Custom Column" from the dropdown menu.

3. In the "Custom Column" dialog box, enter a name for the new column, such as "LnValues".

4. In the "Custom Column" dialog box, enter the following formula:


Number.Ln([Values])


5. Click "OK" to create the new column.

The above formula applies the Number.Ln function to each value in the "Values" column and returns the natural logarithm of each value. The results are added as a new column called "LnValues".

The Number.Ln function in Power Query is a useful tool for calculating the natural logarithm of a given number. In this article, we explored the M code behind the function and saw how it can be used in data analysis projects. By understanding the M code behind this function, you can gain a better understanding of how Power Query works and how you can use it to solve complex data analysis problems.

Power Query and M Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us

    Subject

    Your Name (required)

    Company/Organisation

    Email (required)

    Telephone

    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)