# Number.Factorial

## #

In this article, we will explore the M code behind the Number.Factorial function, its syntax, parameters, and usage. So, let’s dive in!

## Syntax

The syntax of the Number.Factorial function is as follows:

Number.Factorial(number)

``` Here, number is the input for which the factorial needs to be calculated. It must be a non-negative integer. Parameters The Number.Factorial function has only one parameter, which is the input number. Usage The Number.Factorial function is used to calculate the factorial of a given number. A factorial of a number is the product of all positive integers from 1 to that number. For example, the factorial of 5 (written as 5!) is calculated as follows: ```

5! = 5 x 4 x 3 x 2 x 1 = 120

``` Here, the factorial of 5 is calculated by multiplying all positive integers from 1 to 5. The Number.Factorial function can be used in Power Query to calculate the factorial of a column of integers. Let's see an example. Suppose we have a table named 'Numbers' with a column named 'Num' that contains integers. We want to calculate the factorial of each number in the 'Num' column and create a new column named 'Factorial' with the calculated values. To achieve this, we can use the following M code: ```

let

Source = Numbers,

``` In the above M code, we first create a variable named 'Source' that refers to the 'Numbers' table. Then we add a custom column named 'Factorial' to the table using the 'Table.AddColumn' function. The 'each' keyword is used to apply the Number.Factorial function to each value in the 'Num' column. Finally, we return the updated table with the new 'Factorial' column. The Number.Factorial function is a powerful tool in Power Query that allows us to calculate the factorial of a given number. This function is extensively used in data transformations and data cleansing activities in both Power Query and Power BI. By understanding the syntax, parameters, and usage of this function, we can leverage its power to solve complex data problems and gain insights from our data. 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) ```
``` ```
``` ```
``` ```
``` ```
``` ```