Number.Factorial
NumberReturns the factorial of a non-negative integer (n! = 1 × 2 × ... × n).
Syntax
Number.Factorial(number as number) as numberParameters
| Name | Type | Required | Description |
|---|---|---|---|
number | number | Yes | A non-negative integer whose factorial is computed. Must be a whole number >= 0. |
Return Value
number — The factorial of the given non-negative integer.
Remarks
Number.Factorial computes n! — the product of all positive integers from 1 up to n. By convention, 0! = 1 (the empty product). The input must be a non-negative integer; passing a negative number or a fractional value raises an error.
Factorial values grow extremely rapidly: 10! = 3,628,800; 20! ≈ 2.4 × 10^18; 170! ≈ 7.3 × 10^306 (near the double-precision limit). Number.Factorial(171) returns infinity because the result overflows IEEE 754 double-precision. Do not use factorial to directly compute large combinatorics — use Number.Combinations or Number.Permutations instead, as those functions are implemented to avoid the intermediate factorial overflow.
Factorials are the mathematical foundation for: combinatorics (C(n,k) = n! / (k!(n-k)!)), permutations (P(n,k) = n! / (n-k)!), and probability distributions (Poisson, binomial). In Power Query they are most useful for small n in lookup tables, educational examples, or computing factorial-based normalizing constants.
Examples
Example 3: Verify the combinations formula using factorials
let
N = 5,
K = 2,
Computed = Number.Factorial(N) / (Number.Factorial(K) * Number.Factorial(N - K))
in
ComputedThe final output — C(5,2) = 10, confirming there are 10 ways to choose 2 items from 5.
Result | |
|---|---|
| 1 | 10 |