Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredJoin 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.
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.
Solved! Go to Solution.
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
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
@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.
Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!
Check out the October 2025 Power BI update to learn about new features.
User | Count |
---|---|
85 | |
42 | |
30 | |
27 | |
26 |