OpenBI Docs Buy

Number.Random

A random number from 0 up to, but not including, 1.

Group: Number. Power Query M has it too: a query that uses it is written as in Power BI.

Syntax

Number.Random() as number

It takes no parameters.

Returns

number. A number at least 0 and below 1.

Remarks

  • Each call gives another number, and each refresh new ones: nothing is repeated from one run to the next.
  • Scale it for other ranges: times 100, rounded down, plus 1 gives a whole number from 1 to 100. Number.RandomBetween scales it for you.
  • For a fixed sequence that a refresh gives again, use List.Random with a seed.

Compared with Power Query

Known difference in OpenBI Studio 0.3.79, found while this page was written and run on its engine:

  • List.Count(List.Distinct(Table.AddColumn(#table({"Order"}, {{1}, {2}, {3}}), "R", each Number.Random())[R])): Power Query gives 1: in a column added with Table.AddColumn (or changed with Table.TransformColumns), every row gets the same random number, and the model loads it so. A Table.Buffer around the added column's table, or Number.RandomBetween, gives each row its own. OpenBI gives each row its own number: 3.

Examples

A random fraction

Number.Random()
0.8065618251888952

A random whole number from 1 to 100

Number.RoundDown(Number.Random() * 100) + 1
66

Number.RandomBetween, List.Random, Number.RoundDown, Table.AddColumn.

Last updated · OpenBI Studio 0.3.79