RAND

Updated on

RAND is a DAX function that returns a random number between 0 (inclusive) and 1 (exclusive), which changes upon recalculation.

Syntax

RAND( )

Return Values

A decimal number.

Remarks

  • Recalculation depends on various factors, including whether the model is set to Manual or Automatic recalculation mode, and whether data has been refreshed.

  • RAND and other volatile functions that do not have fixed values are not always recalculated. For example, execution of a query or filtering will usually not cause such functions to be re-evaluated. However, the results for these functions will be recalculated when the entire column is recalculated. These situations include refresh from an external data source or manual editing of data that causes re-evaluation of formulas that contain these functions.

  • RAND is always recalculated if the function is used in the definition of a measure.

  • RAND function cannot return a result of zero, to prevent errors such as division by zero.

Examples

To generate a random real number between two other numbers, use:

= RAND()*(b-a)+a

To generate a random number greater than 0 and less than 1:

= RAND()

To generate a random number greater than 0 and less than 100

= RAND()*100

To generate a random whole number greater than 0 and less than 100

INT(RAND()*100)

Other functions related to RAND are:

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/dax/rand-function-dax

2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy