Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
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.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 56 | |
| 40 | |
| 36 | |
| 20 | |
| 18 |
| User | Count |
|---|---|
| 74 | |
| 72 | |
| 38 | |
| 35 | |
| 26 |