RAND DAX Function (Math and Trig) Volatile

Returns a random number greater than or equal to 0 and less than 1, evenly distributed. Random numbers change on recalculation.

Syntax

RAND ( )

This expression has no parameters.

Return values

Scalar A single decimal value.

A random number.

» 1 related article
» 1 related function

Examples

--  RAND returns a random number between 0 and 1
--  RANDBETWEEN returns a random number between 
--  the two provide boundaries
DEFINE 
    VAR Vals = GENERATESERIES ( 1, 10, 1 )
VAR Random = 
    ADDCOLUMNS ( 
        Vals,
        "RAND",        RAND (),
        "RANDBETWEEN", RANDBETWEEN (-[Value], +[Value] )
    )
EVALUATE
    Random
EVALUATE
    {
        ( "Random Average (around 0.5)",  AVERAGEX ( Random, [RAND] ) ),
        ( "RandBetween Avg (near 0)",      AVERAGEX ( Random, [RANDBETWEEN] ) ),
        ( "RandBetween Min (near -10000)", MINX ( Random, [RANDBETWEEN] ) ),
        ( "RandBetween Max (near  10000)", MAXX ( Random, [RANDBETWEEN] ) )
    }
Value RAND RANDBETWEEN
1 0.31 0
2 0.87 2
3 0.54 0
4 0.91 1
5 0.24 3
6 0.40 2
7 0.39 -6
8 0.40 6
9 0.99 -6
10 0.41 1
Value1 Value2
Random Average (around 0.5) 0.55
RandBetween Avg (near 0) 0.30
RandBetween Min (near -10000) -6.00
RandBetween Max (near 10000) 6.00

Related articles

Learn more about RAND in the following articles:

Related functions

Other related functions are:

Last update: Nov 14, 2024   » Contribute   » Show contributors

Contributors: Alberto Ferrari, Marco Russo

Microsoft documentation: https://docs.microsoft.com/en-us/dax/rand-function-dax

2018-2024 © SQLBI. All rights are reserved. Information coming from Microsoft documentation is property of Microsoft Corp. » Contact us   » Privacy Policy & Cookies

Context Transition

This function performs a Context Transition if called in a Row Context. Click to read more.

Row Context

This expression is executed in a Row Context. Click to read more.

Iterator

Not recommended

The use of this function is not recommended. See Remarks and Related functions for alternatives.

Not recommended

The use of this parameter is not recommended.

Deprecated

This function is deprecated. Jump to the Alternatives section to see the function to use.

Volatile

A volatile function may return a different result every time you call it, even if you provide the same arguments. Click to read more.

Deprecated

This parameter is deprecated and its use is not recommended.

DirectQuery compatibility

Limitations are placed on DAX expressions allowed in measures and calculated columns.
The state below shows the DirectQuery compatibility of the DAX function.

Contribute

Want to improve the content of RAND? Did you find any issue?
Please, report it us! All submissions will be evaluated for possible updates of the content.


This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.