cancel
Showing results for
Did you mean:

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a \$100 discount. Register Now

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
Community Support

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:

(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:

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

You can click

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”.

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

Then you can click

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

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.

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

3 REPLIES 3
Community Support

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:

(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:

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

You can click

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”.

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

Then you can click

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

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.

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

Frequent Visitor

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.

Announcements

#### Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

#### Power BI Monthly Update - February 2024

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

#### Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

#### Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors