Number.Factorial

Number

Returns the factorial of a non-negative integer (n! = 1 × 2 × ... × n).

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

Number.Factorial(number as number) as number

Parameters

NameTypeRequiredDescription
numbernumberYesA non-negative integer whose factorial is computed. Must be a whole number >= 0.

Return Value

numberThe 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 1: Factorial of 5

Result
Result
1120

Example 2: Factorial of 0 — by convention equals 1

Result
Result
11

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
    Computed
Applied Steps

The final output — C(5,2) = 10, confirming there are 10 ways to choose 2 items from 5.

Result
110

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks