Number.Sign

D

T

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

Understanding the Number.Sign Function

The Number.Sign function is a simple but powerful function that is used to determine the sign of a number. The function takes a single argument, which is the number that you want to determine the sign of. The function then returns -1 if the number is negative, 0 if the number is zero, and 1 if the number is positive.

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


Number.Sign(number)


Here, number is the number that you want to determine the sign of.

The M Code Behind the Number.Sign Function

The M code behind the Number.Sign function is relatively simple. The function is defined as follows:


Number.Sign = (number as number) as number =>

if number < 0 then

-1

else if number > 0 then

1

else

0


Here, we define the Number.Sign function and specify that it takes a single argument, which is a number. We then use an if-else statement to determine the sign of the number. If the number is less than 0, we return -1. If the number is greater than 0, we return 1. Finally, if the number is equal to 0, we return 0.

Using the Number.Sign Function in Power Query M

The Number.Sign function is a very useful function that can be used in a variety of ways in Power Query M. One common use of the function is to determine the sign of a value in a table. For example, suppose that you have a table called "Sales" that contains a column called "Revenue". You can use the Number.Sign function to create a new column that indicates whether each revenue value is positive or negative. To do this, you can use the following steps:

1. Open the "Sales" table in the Power Query Editor.

2. Click on the "Add Column" tab in the ribbon.

3. Click on the "Custom Column" button.

4. In the "Custom Column" dialog box, enter a name for the new column (e.g. "Revenue Sign").

5. In the "Custom column formula" box, enter the following formula: `Number.Sign([Revenue])`.

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

Once you have created the new column, you can use it to filter or group the data as needed.

The Number.Sign function is a simple but powerful function in Power Query M that allows users to determine the sign of a number. The M code behind the function is relatively simple, using an if-else statement to determine the sign of the number. The function can be used in a variety of ways in Power Query M, including to create new columns in tables. By understanding the M code behind the Number.Sign function, you can gain a better understanding of how Power Query M works and how to use it to transform your data.

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)