RANDBETWEEN DAX Function (Math and Trig) Volatile

Returns a random number between the numbers you specify.

Syntax

RANDBETWEEN ( <Bottom>, <Top> )
Parameter Attributes Description
Bottom

The smallest integer RANDBETWEEN will return.

Top

The largest integer RANDBETWEEN will return.

Return values

Scalar A single integer value.

A random integer number between Bottom and Top, which are included in the range of the possible integer results.
If Bottom is greater than Top, then RANDSBETWEEN raises an error.

» 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 functions

Other related functions are:

Last update: Mar 27, 2024   » Contribute   » Show contributors

Contributors: Alberto Ferrari, Marco Russo, Kenneth Barber

Microsoft documentation: https://docs.microsoft.com/en-us/dax/randbetween-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 RANDBETWEEN? 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.