Forum Discussion
Unable to filter Top-N using parameters.
- 5 months ago
Hi abhi201002 ,
Thanks for the clarification, what you’re seeing is due to how evaluation context is affecting your measures. The main issue is the use of ALLSELECTED() in your RANKX, which makes the ranking dependent on the current filter context rather than the full customer set. As a result, the rank gets recalculated inconsistently (e.g., collapsing to only 1 customer at 100%, all 0s below that, and partial results above 100%).
Additionally, using a measure (Dynamic Filter) that depends on rank as a visual-level filter creates a feedback loop where the filter and ranking influence each other. Your expectation (Top 5 for 5%, Top 50 for 50%) is absolutely valid, but it requires ranking over a stable, unfiltered dataset. You can partially improve this by replacing ALLSELECTED with ALL, but for consistent and scalable results, the TOPN-based approach is recommended as it avoids these context issues entirely.The TOPN based approach works by calculating the TopN customers in a separate virtual table, instead of relying on ranking inside the visual. First, you convert your percentage slicer into a number of customers:
Top N Customers =
VAR Pct = SELECTEDVALUE('%Top Customer'[%Top Customer], 1)
VAR TotalCust = DISTINCTCOUNT(Orders[Customer ID])
RETURN
MAX(1, INT(Pct * TotalCust))Then, you build a virtual table of the top customers using TOPN:
TopN Filter =
VAR N = [Top N Customers]
VAR TopTable =
TOPN(
N,
ADDCOLUMNS(
VALUES(Orders[Customer ID]),
"@Sales", [Total Sales]
),[@Sales], DESC)
RETURN
IF(
ISINSCOPE(Orders[Customer ID]) &&
Orders[Customer ID] IN TopTable,
1,0)Finally, apply TopN Filter = 1 as a visual-level filter.
If further assistance is still required.Please provide the sample Pbix file. How to provide sample data in the Power BI Forum
You can refer the following link to upload the file to the community.
How to upload PBI in CommunityWe are available to support you and are committed to helping you reach a resolution.
Best Regards,
Chaithra E.
Hi abhi201002 ,
Just checking in to see if you had a chance to follow up on our earlier conversation. If you're still encountering the issue, please share the sample data so we can assist you with an accurate solution.
If you have any further questions, feel free to reach out anytime.
Thank you.