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.
There are two slicers. 1. Choose Top or Bottom 2.Choose value like 1,2,3 etc.
Can you tell where it is getting wrong?
Solved! Go to Solution.
Hi @prathmeshb27 ,
Here is the updated code :
Dax
Dynamic Time Period with Top Rank =
VAR N = SELECTEDVALUE('Top N Value'[Top N Value])
VAR RankType = SELECTEDVALUE('TopBottom Selector'[RankType])
VAR IsTop = RankType = "Top"
VAR IsBottom = RankType = "Bottom"
VAR BaseMeasure = [Dynamic Time Period Measure]
// Create a table of products with non-blank measure values
VAR ProductTable =
FILTER(
ALLSELECTED(Products[ProductName]),
NOT ISBLANK(CALCULATE([Dynamic Time Period Measure]))
)
// Rank products based on the selected measure
VAR ProductRankTop =
RANKX(
ProductTable,
CALCULATE([Dynamic Time Period Measure]),
,
DESC
)
VAR ProductRankBottom =
RANKX(
ProductTable,
CALCULATE([Dynamic Time Period Measure]),
,
ASC
)
RETURN
SWITCH(
TRUE(),
IsTop && ProductRankTop <= N, BaseMeasure,
IsBottom && ProductRankBottom <= N, BaseMeasure,
BLANK()
)
⭐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]
Hi
You would need to change your measure as per the steps below
Steps
1. Create a Combined Entity Table
You need a table that contains both products and regions as rows. This can be done in Power Query or by using DAX to create a calculated table:
CombinedEntityTable =
UNION(
SELECTCOLUMNS(Products, "EntityType", "Product", "EntityName", Products[ProductName]),
SELECTCOLUMNS(Regions, "EntityType", "Region", "EntityName", Regions[RegionName])
)
2. Update the Measure for Dynamic Ranking
DAX
Dynamic Top Bottom N Entity =
VAR N = SELECTEDVALUE('Top N Value'[Top N Value])
VAR RankType = SELECTEDVALUE('TopBottom Selector'[RankType])
VAR IsTop = RankType = "Top"
VAR IsBottom = RankType = "Bottom"
// Replace this SWITCH with your actual metric selection logic if needed
VAR SelectedMeasure =
[Dynamic Time Period Measure]
// Build a table of all entities with non-blank values for the selected measure
VAR EntityTable =
FILTER(
ALLSELECTED('CombinedEntityTable'[EntityName]),
NOT ISBLANK(CALCULATE(SelectedMeasure))
)
// Calculate the Top and Bottom ranks
VAR EntityRankTop =
RANKX(
EntityTable,
CALCULATE(SelectedMeasure),
,
DESC
)
VAR EntityRankBottom =
RANKX(
EntityTable,
CALCULATE(SelectedMeasure),
,
ASC
)
RETURN
SWITCH(
TRUE(),
IsTop && EntityRankTop <= N, SelectedMeasure,
IsBottom && EntityRankBottom <= N, SelectedMeasure,
BLANK()
)
⭐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]
What if we need to display Top N/Bottom N products and regions both.
It should show only top 5 or bottom 5 products and regions. Only 5 row table.
Like this?
Hi @prathmeshb27 ,
Looking at your question, it seems that you are facing following issues :
Your matrix visual shows the Top 5 products based on the dynamic time period measure — working as expected.
Your current DAX logic only returns a value when ranking condition is met (Top or Bottom), but it does not handle the case when the slicer is not set properly or RankType is blank, or there's a logic flaw in the SWITCH/IF conditions.
Also, you’re using SWITCH(RankType, ...), which won't handle "Bottom" properly unless the RankType slicer value is exactly "Bottom" — and if it's blank or not selected, it'll return nothing.
We can fix this by following steps :
Here’s the updated DAX measure that should fix your issue:
DAX
Dynamic Time Period with Top Rank =
VAR N = SELECTEDVALUE('Top N Value'[Top N Value])
VAR RankType = SELECTEDVALUE('TopBottom Selector'[RankType])
VAR ProductRankTop =
RANKX(
ALLSELECTED(Products[ProductName]),
[Dynamic Time Period Measure],
,
DESC
)
VAR ProductRankBottom =
RANKX(
ALLSELECTED(Products[ProductName]),
[Dynamic Time Period Measure],
,
ASC
)
RETURN
SWITCH(
TRUE(),
RankType = "Top" && ProductRankTop <= N, [Dynamic Time Period Measure],
RankType = "Bottom" && ProductRankBottom <= N, [Dynamic Time Period Measure],
BLANK()
)
Ensure your slicer values are exactly "Top" or "Bottom" (no spaces or typos).
Confirm Dynamic Time Period Measure returns values across products (not blank for some).
If needed, add a card visual showing SELECTEDVALUE('TopBottom Selector'[RankType]) to confirm what’s being captured.
⭐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]
Still not wokring and this is answer from CHATGPT and i have already tried this.
Hi @prathmeshb27 ,
Here is the updated code :
Dax
Dynamic Time Period with Top Rank =
VAR N = SELECTEDVALUE('Top N Value'[Top N Value])
VAR RankType = SELECTEDVALUE('TopBottom Selector'[RankType])
VAR IsTop = RankType = "Top"
VAR IsBottom = RankType = "Bottom"
VAR BaseMeasure = [Dynamic Time Period Measure]
// Create a table of products with non-blank measure values
VAR ProductTable =
FILTER(
ALLSELECTED(Products[ProductName]),
NOT ISBLANK(CALCULATE([Dynamic Time Period Measure]))
)
// Rank products based on the selected measure
VAR ProductRankTop =
RANKX(
ProductTable,
CALCULATE([Dynamic Time Period Measure]),
,
DESC
)
VAR ProductRankBottom =
RANKX(
ProductTable,
CALCULATE([Dynamic Time Period Measure]),
,
ASC
)
RETURN
SWITCH(
TRUE(),
IsTop && ProductRankTop <= N, BaseMeasure,
IsBottom && ProductRankBottom <= N, BaseMeasure,
BLANK()
)
⭐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]
User | Count |
---|---|
75 | |
75 | |
45 | |
31 | |
27 |
User | Count |
---|---|
99 | |
89 | |
52 | |
48 | |
46 |