Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
ardianfirman06
Frequent Visitor

DAX Random Sample with criteria 5% of the volume

Hi, 

 

Is there any way to create a random sample with criteria of 5% of the volume from each category

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi @ardianfirman06 ,

According to your description You want to create a random sample of the aggregated value(Volume: 0-5%) grouped by a certain column.Right?

Here are the steps you can follow:

(1)This is my test data:

vyangliumsft_0-1661495029647.png

(2)If you want to create a random sample in visual, you can create a measure:

ran_value = SUM(Table1[value])*RAND()*5/100

Then you can put it in your visual like this:

vyangliumsft_1-1661495029655.png

If you don’t want to have the “Total”, you can close it in Format Pane.

vyangliumsft_2-1661495029659.png

You can click

vyangliumsft_3-1661495029660.png

 to recalculate the value of this measure to achieve a random sample.

(3)If you want to create a random sample in table, you can click “new table”.

vyangliumsft_4-1661495029661.png

Table = SELECTCOLUMNS( SUMMARIZE('Table1','Table1'[name],"Sum Value",SUM(Table1[value])) , "name",[name],"Ran Value",[Sum Value] * RAND()*5/100)

Then you can click

vyangliumsft_5-1661495029661.png

to recalculate the table to achieve a random sample, like this:

vyangliumsft_6-1661495029663.png

If this solution is different from your needs, can you share sample data and sample output in table format? Or a ample .pbix file after removing sensitive data. We can better understand the problem and help you.

 

If you need pbix, please click here.

case_02.pbix

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

3 REPLIES 3
v-yangliu-msft
Community Support
Community Support

Hi @ardianfirman06 ,

According to your description You want to create a random sample of the aggregated value(Volume: 0-5%) grouped by a certain column.Right?

Here are the steps you can follow:

(1)This is my test data:

vyangliumsft_0-1661495029647.png

(2)If you want to create a random sample in visual, you can create a measure:

ran_value = SUM(Table1[value])*RAND()*5/100

Then you can put it in your visual like this:

vyangliumsft_1-1661495029655.png

If you don’t want to have the “Total”, you can close it in Format Pane.

vyangliumsft_2-1661495029659.png

You can click

vyangliumsft_3-1661495029660.png

 to recalculate the value of this measure to achieve a random sample.

(3)If you want to create a random sample in table, you can click “new table”.

vyangliumsft_4-1661495029661.png

Table = SELECTCOLUMNS( SUMMARIZE('Table1','Table1'[name],"Sum Value",SUM(Table1[value])) , "name",[name],"Ran Value",[Sum Value] * RAND()*5/100)

Then you can click

vyangliumsft_5-1661495029661.png

to recalculate the table to achieve a random sample, like this:

vyangliumsft_6-1661495029663.png

If this solution is different from your needs, can you share sample data and sample output in table format? Or a ample .pbix file after removing sensitive data. We can better understand the problem and help you.

 

If you need pbix, please click here.

case_02.pbix

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Thank you for this. this is really help.

 

is there any function that we can use to keep the sample ? so the table of sampling wont changed on every running and increase the sample if there is additional data ingested to the source table.

amitchandak
Super User
Super User

@ardianfirman06 , refer if these can help

https://community.powerbi.com/t5/Desktop/DAX-random-sample/m-p/386571

https://chandoo.org/wp/power-query-random-sample/

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.