Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi Experts
I am trying to get the following out come based on the slicer selection criteria....
1. If the user selects Gross Margin (first slicer) and then Reported (second slicer) then return the Top 10 Products based on the Reported measure...
2. If the user selects Gross Margin (first slicer) and then NOE (second slicer) then return the Top 10 Products based on the NOE measure...
else
3. If the user selects Gross Margin (first slicer) and nothing on second slicer then return the Top 10 Products based on the Gross Margin measure.....
Cannot get the formula to work....
Top Products Reported:- Gross Margin / Net Sales =
VAR RankingContext = VALUES('Product'[Category])
VAR ProfitbabilityMeasure = SELECTEDVALUE(ProfitabilityMeasures[MeasureName])
VAR ReportingMeasure = SELECTEDVALUE(Reporting[Reporting])
RETURN
CALCULATE(SWITCH(TRUE(),AND(
ProfitbabilityMeasure = "Gross Margin",
ReportingMeasure = "Reported"), [GMvPY1% (Reported PY)],
TOPN(10, ALL('Product'[Category]),[GMvPY1% (Reported PY)]),
AND(
ProfitbabilityMeasure = "Gross Margin",
ReportingMeasure = "NOE"), [GMvPY3% (NOE @ PY Rate)],
TOPN(10, ALL('Product'[Category]),[GMvPY3% (NOE @ PY Rate)]),
ProfitbabilityMeasure = "Gross Margin",[GMvPY1% (Reported PY)],
TOPN(10, ALL('Product'[Category]),[GMvPY1% (Reported PY)]),
RankingContext,BLANK(),0)
)
Solved! Go to Solution.
SWITCH, just like IF, cannot return a table expression.
Have you tried something like this?
SWITCH(TRUE(),
ProfitbabilityMeasure = "Gross Margin" && ReportingMeasure = "Reported"
, CALCULATE( [GMvPY1% (Reported PY)]
, TOPN(10, ALL('Product'[Category]),[GMvPY1% (Reported PY)])
)
, ...
)
SWITCH, just like IF, cannot return a table expression.
Have you tried something like this?
SWITCH(TRUE(),
ProfitbabilityMeasure = "Gross Margin" && ReportingMeasure = "Reported"
, CALCULATE( [GMvPY1% (Reported PY)]
, TOPN(10, ALL('Product'[Category]),[GMvPY1% (Reported PY)])
)
, ...
)
Thanks for the excellent feedback,,,
I am guess we need to add RankingContext
))
to th eend of the statement...
got it to work....thanks
Hi this is my full measure....cannot see my error...
Top Products Reported:- Gross Margin / Net Sales =
VAR RankingContext = VALUES('Product'[Category])
VAR ProfitbabilityMeasure = SELECTEDVALUE(ProfitabilityMeasures[MeasureName])
VAR ReportingMeasure = SELECTEDVALUE(Reporting[Reporting])
RETURN
SWITCH(TRUE(),
ProfitbabilityMeasure = "Gross Margin" && ReportingMeasure = "Reported"
, CALCULATE( [GMvPY1% (Reported PY)]
, TOPN(10, ALL('Product'[Category]),[GMvPY1% (Reported PY)])),
RankingContext,
ProfitbabilityMeasure = "Gross Margin" && ReportingMeasure = "NOE"
, CALCULATE( [GMvPY3% (NOE @ PY Rate)]
, TOPN(10, ALL('Product'[Category]),[GMvPY3% (NOE @ PY Rate)]),
RankingContext,
ProfitbabilityMeasure = "Gross Margin"
, CALCULATE( [GMvPY1% (Reported PY)]
, TOPN(10, ALL('Product'[Category]),[GMvPY1% (Reported PY)]),
RankingContext)))
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 39 | |
| 37 | |
| 33 | |
| 32 | |
| 29 |
| User | Count |
|---|---|
| 133 | |
| 88 | |
| 85 | |
| 68 | |
| 64 |