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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
AC_DATA
Frequent Visitor

Return dynamically sized sample based on row count from table filtered by user-selected dates

I have a complex request to be able to select a sample of data for auditing based on user-selected dates. My current approach is to have a date slicer so the user can select the date range and create a calculated table that is using the SAMPLE function to return sample data from another table.

The problem is that I want to have the size of the sample dynamically related to the number of total rows in the date range. My approach would be to calculate the number of rows based on the user-filtered date range and multiply that number by a decimal then pass that number into the SAMPLE function. However, I cannot seem to find a way to do that.

 

For clarity, here is a simple example:

The data set spans 30 days and each day has between 5 and 10 records. The user selects a range of 5 days which has a total filtered row count of 40 (3 days with 10 records and 2 days with 5 records). I want to return only 10% of the records as a sample so the 40 records times 10% equals 4 and that number would be passed into the sample function for the calculated table. If the user then selects a different range with 70 records, the calculated sample table would return 7 records.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @AC_DATA ,

 

Use count() function to calculate the count rows of filtered table and use this count * 10%. Then use this number in the SAMPLE() function. This number could be a decimal number, you could use roundup() or rounddown() function to make it a whole number.

 

Best Regards,

Jay

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @AC_DATA ,

 

Use count() function to calculate the count rows of filtered table and use this count * 10%. Then use this number in the SAMPLE() function. This number could be a decimal number, you could use roundup() or rounddown() function to make it a whole number.

 

Best Regards,

Jay

Greg_Deckler
Community Champion
Community Champion

@AC_DATA That should be something like:

Measure =
  VAR __Count = COUNTROWS('Table') //the filtered table
  VAR __SampleSize = __Count * .1
RETURN
  SAMPLE(__SampleSize, ...)

Hard to be specific. Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.