Forum Discussion
Based on slicer selection it should change the visual data.
For example, I have a fiscal period slicer that includes two columns Fiscal Month (a direct column) and Latest Closed Period Sales (a calculated column).
In my table, I have three columns: Account, Opportunity, and Gross Margin.
When I select all months in the fiscal period slicer, the table should display the top 5 opportunities.
When I select a single month in the slicer, it should still display the same top 5 opportunities that appeared when all months were selected.
5 Replies
- GrowthNatives
Super User
Hi Poojajunnu , you’re asking for dynamic context control in Power BI: when all months are selected, show the Top 5 opportunities by Gross Margin (normal behavior); but when a single month is selected, freeze that same Top 5 set — i.e., show their monthly data, but not re-rank them.
That’s a subtle but powerful trick because Power BI re-applies filter context every time you slice, so the “Top 5” naturally changes. To lock that Top 5 while still allowing other visuals (like fiscal months) to update, we’ll need a DAX measure that remembers which opportunities were top 5 in the “all months” context.
Step-by-step setup
Step 1. Define your base measure
Gross Margin = SUM('YourTable'[Gross Margin])Step 2. Create a measure to identify Top 5 Opportunities (in all-month context)
We use ALLSELECTED() to evaluate all fiscal months regardless of current slicer selection.
Top 5 Opp Flag = VAR Top5Opps = TOPN( 5, ADDCOLUMNS( VALUES('YourTable'[Opportunity]), "@GM", [Gross Margin] ), [@GM], DESC ) RETURN IF( 'YourTable'[Opportunity] IN Top5Opps, 1, 0 )This measure returns 1 for those opportunities that were in the Top 5 when all months were visible in the slicer.
Step 3. Create your display measure for Gross Margin
Now create a measure that filters based on that flag:
Gross Margin (Top 5) = CALCULATE( [Gross Margin], KEEPFILTERS( FILTER( ALL('YourTable'[Opportunity]), [Top 5 Opp Flag] = 1 ) ) )This ensures that regardless of what fiscal month is selected, your table only includes the same 5 opportunities.
Step 4. Build your table visual
Rows: Account, Opportunity
Values: Gross Margin (Top 5)
Slicer: Fiscal Period (with both columns)
Now when:
You select all months → The Top 5 are calculated normally.
You select a single month → The same Top 5 (from the “all months” state) are displayed, showing their data for that period.
Optional: Make it dynamically aware
If you want the behavior to depend only on whether all months or a single month are selected, we can add logic to toggle it automatically:
Gross Margin (Top 5 Dynamic) = VAR MonthCount = DISTINCTCOUNT('Fiscal'[Fiscal Month]) VAR IsSingleMonth = MonthCount = 1 VAR Top5Opps = TOPN( 5, ADDCOLUMNS( VALUES('YourTable'[Opportunity]), "@GM", CALCULATE([Gross Margin], ALL('Fiscal'[Fiscal Month])) ), [@GM], DESC ) RETURN CALCULATE( [Gross Margin], KEEPFILTERS( FILTER( ALL('YourTable'[Opportunity]), IF(IsSingleMonth, 'YourTable'[Opportunity] IN Top5Opps, TRUE()) ) ) )This version dynamically locks the Top 5 only when a single month is selected — otherwise it behaves normally.
⭐Hope this solution helps you make the most of Power BI! If it did, click 'Mark as Solution' to help others find the right answers.
💡Found it helpful? Show some love with kudos 👍 as your support keeps our community thriving!
🚀Let’s keep building smarter, data-driven solutions together!🚀 [Explore More] - PoojajunnuFrequent Visitor
This scnerio is not working.
- AnonymousNot applicable
Hi Poojajunnu ,
I have tried to look for possible solutions to your issue, but could not because of lack os some valuable data.Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Please show the expected outcome based on the sample data you provided.
Thank you - AnonymousNot applicable
Hi Poojajunnu
I wanted to check if you had the opportunity to review to provide the requested information. Please feel free to contact us if you have any further questions.
Thank you. - AnonymousNot applicable
Hi Poojajunnu
May I check if this issue has been resolved? If not, Please feel free to contact us if you have any further questions.
Thank you