Number.RandomBetween
NumberReturns a random number between bottom and top (inclusive).
Syntax
Number.RandomBetween(bottom as number, top as number) as numberParameters
| Name | Type | Required | Description |
|---|---|---|---|
bottom | number | Yes | The minimum value of the random range (inclusive). |
top | number | Yes | The maximum value of the random range (inclusive). |
Return Value
number — A pseudo-random number in the range [bottom, top].
Remarks
Number.RandomBetween returns a pseudo-random floating-point number uniformly distributed in the range [bottom, top] — both endpoints inclusive. It is equivalent to bottom + Number.Random() * (top - bottom).
Non-determinism warning: like Number.Random, this function produces a different value on every call and on every refresh. Results are not reproducible across query evaluations, and there is no built-in seed mechanism. Use Number.RandomBetween only in scenarios where non-determinism is acceptable — for example, generating sample data, adding random jitter to test data, or simulating distributions.
The bottom value must be less than or equal to top. Both parameters accept decimal (fractional) values. Number.RandomBetween returns a floating-point number even when both bounds are integers — to get random integers, wrap with Number.RoundDown(Number.RandomBetween(min, max)) or use Int64.From(Number.RoundDown(...)).
When used inside Table.AddColumn with each, Power Query typically evaluates the function once per row, producing different values per row. However, this behavior can vary depending on the host environment and query folding. If per-row uniqueness is critical, test your specific setup.
Examples
Example 1: A random floating-point number between 1 and 100
Number.RandomBetween(1, 100)Result | |
|---|---|
| 1 | 73.42 |
Example 2: Simulate a random price adjustment between -5% and +5%
Number.RandomBetween(-0.05, 0.05)Result | |
|---|---|
| 1 | 0.02 |
Example 3: Add a random discount percentage column to Sales rows
Table.AddColumn(
Table.SelectColumns(Table.FirstN(Sales, 4), {"OrderID", "CustomerName", "UnitPrice"}),
"DiscountPct",
each Number.Round(Number.RandomBetween(0, 0.3), 2),
type number
)OrderID | CustomerName | UnitPrice | DiscountPct | |
|---|---|---|---|---|
| 1 | 1 | Alice | 25 | 0.12 |
| 2 | 2 | Bob | 50 | 0.27 |
| 3 | 3 | Charlie | 15 | 0.05 |
| 4 | 4 | Alice | 75 | 0.19 |