Number.RandomBetween

Number

Returns a random number between bottom and top (inclusive).

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

Syntax

Number.RandomBetween(bottom as number, top as number) as number

Parameters

NameTypeRequiredDescription
bottomnumberYesThe minimum value of the random range (inclusive).
topnumberYesThe maximum value of the random range (inclusive).

Return Value

numberA 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

Result
Result
173.42

Example 2: Simulate a random price adjustment between -5% and +5%

Result
Result
10.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
)
Result
OrderID
CustomerName
UnitPrice
DiscountPct
11Alice250.12
22Bob500.27
33Charlie150.05
44Alice750.19

Compatibility

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