Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Solved! Go to Solution.
Hi @Anonymous ,
Based on your description, it seems you are looking to create a sampling process that selects a fixed percentage of records from a dataset, grouped by a specific field (`LCCB_SYS_ID`), and that this process is influenced by slicers on your report page.
Please try below steps:
1. Data Preparation:
- Import your dataset into Power BI and perform any necessary data cleanup.
- Add an index column to ensure each row has a unique identifier.
- Add a column with a random number to be used for random sampling.
2. Creating Measures:
- Create a measure to calculate the number of changes required for sampling based on the percentage defined for each group. For example:
SampleSize = ROUNDUP(CALCULATE(COUNT('SOPDerived'[CHANGE_NUMBER]) * 0.20), 0)
- Ensure that this measure updates correctly based on the page slicers.
3. Sampling Logic:
- To select the top N items based on the random number column, you can use the `TOPN` function in combination with a filter or calculated table. However, measures cannot be directly used in the `TOPN` function since they do not return a table. Instead, you can use a calculated column or a calculated table to achieve this.
- Here's an example of how you might create a calculated table that takes the top N items based on your sample size measure:
SampledChanges =
VAR SampleSize = [SampleSize] -- This is your measure from step 2
RETURN
TOPN(
SampleSize,
ALL('SOPDerived'),
'SOPDerived'[RandomColumn], -- This is the column with random numbers
ASC
)
- This calculated table will dynamically update based on the measure, which in turn is influenced by the slicers.
4. Export to Excel:
- Once you have your sampled data, you can export it to Excel by using the "Export data" option available in Power BI visuals.
Please note that the calculated table approach may have performance implications depending on the size of your dataset. If you encounter performance issues, consider optimizing your model or sampling within the query editor before loading the data into the model.
Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Anonymous ,
Based on your description, it seems you are looking to create a sampling process that selects a fixed percentage of records from a dataset, grouped by a specific field (`LCCB_SYS_ID`), and that this process is influenced by slicers on your report page.
Please try below steps:
1. Data Preparation:
- Import your dataset into Power BI and perform any necessary data cleanup.
- Add an index column to ensure each row has a unique identifier.
- Add a column with a random number to be used for random sampling.
2. Creating Measures:
- Create a measure to calculate the number of changes required for sampling based on the percentage defined for each group. For example:
SampleSize = ROUNDUP(CALCULATE(COUNT('SOPDerived'[CHANGE_NUMBER]) * 0.20), 0)
- Ensure that this measure updates correctly based on the page slicers.
3. Sampling Logic:
- To select the top N items based on the random number column, you can use the `TOPN` function in combination with a filter or calculated table. However, measures cannot be directly used in the `TOPN` function since they do not return a table. Instead, you can use a calculated column or a calculated table to achieve this.
- Here's an example of how you might create a calculated table that takes the top N items based on your sample size measure:
SampledChanges =
VAR SampleSize = [SampleSize] -- This is your measure from step 2
RETURN
TOPN(
SampleSize,
ALL('SOPDerived'),
'SOPDerived'[RandomColumn], -- This is the column with random numbers
ASC
)
- This calculated table will dynamically update based on the measure, which in turn is influenced by the slicers.
4. Export to Excel:
- Once you have your sampled data, you can export it to Excel by using the "Export data" option available in Power BI visuals.
Please note that the calculated table approach may have performance implications depending on the size of your dataset. If you encounter performance issues, consider optimizing your model or sampling within the query editor before loading the data into the model.
Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Check out the July 2025 Power BI update to learn about new features.
User | Count |
---|---|
97 | |
96 | |
58 | |
45 | |
42 |