Forum Discussion

Christann's avatar
Christann
Advocate IV
8 years ago
Solved

DAX random sample

Is it possible to create a new table in DAX which is a random sample of rows from another table? I would have to be able to refresh the sample table.
  • OwenAuger's avatar
    OwenAuger
    8 years ago

    Hi Christann

     

    To create a random sample table with DAX, I would use RAND() as suggested above, and create a table with an expression like this:

     

    Random Selection =
    VAR SampleSize = 10
    VAR TableWithRand =
        ADDCOLUMNS ( OriginalTable, "Rand", RAND () )
    RETURN
        TOPN ( SampleSize, TableWithRand, [Rand] )

    The Random Selection table will end up with an extra column Rand but you can remove that if needed.

     

    It appears that the SAMPLE function returns a deterministic sample.

     

    Regards,

    Owen