Forum Discussion
DAX random sample
- 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
- OwenAuger8 years agoSuper User
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
- Anonymous5 years agoNot applicable
Hi OwenAuger
This is a fantastic example! Thank you I have found this very helpful.
To delve deeper into this, is it possible to pick a random sample based on certain criteria? For example I have a column with regions and I need to select a random sample of 3% from each region.
At the moment I can make a table which can calculate the number of lines needed per region based on 3% but is it possible to set a table up as in your example to pick a random sample based on the % and region?
Regards,
Gwyneth
- KenTate113 years agoNew Member
I would like to generate a random sample in this same way, but adding a location, date and time criteria to te sample return? For example, 1 row for every hour on each day at each location. Is this possible?