Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

SELECTED VALUE Filters

Hi All,

I have the below syntax. The 'Dimension'[Dimension Fields] is a field parameter. I want to filter based on the field dimension and return the calculation from the fields.

 

SWITCH TOP10 = SWITCH(
TRUE(),
SELECTEDVALUE('Dimension'[Dimension Fields]) = "Orange", CALCULATE([Top 10 - Orange]),
SELECTEDVALUE('Dimension'[Dimension Fields]) = "Apple", CALCULATE([Top 10 - Apple]),
SELECTEDVALUE('Dimension'[Dimension Fields]) = "Grapes", CALCULATE([Top 10 - Grapes]),
SELECTEDVALUE('Dimension'[Dimension Fields]) = "Pineapple", CALCULATE([Top 10 - Pineapple]),
SELECTEDVALUE('Dimension'[Dimension Fields]) = "Avocado", CALCULATE([Top 10 - Avocado])
)


Top 10 - Orange =
CALCULATE( [UnitsVolume],
TOPN( 10, ALL(Fruits[Orange]),[UnitsVolume], DESC ),
VALUES(Fruits[Orange]))


For some reason the SWITCH logic does not work as expected and I get a blank report. The "Top 10 - Orange" calculation works fine when used separately without the SWITCH clause.

Can you please correct the DAX syntax so I can calculate the measures based on the dimension selection?

Thanks

4 REPLIES 4
Anonymous
Not applicable

@rajendraongole1  Thank you very much but I see this

 

GallopPBI_0-1716983289243.png

 

I just tried with one selection criteria

 

SWITCH(
SELECTEDVALUE('Dimension'[Dimension Fields]),

"Orange", CALCULATE([Top 10 - Orange]),

BLANK()

)

 

The CALCULATE([Top 10 - Orange]) calculation is as below

CALCULATE( [Sales],TOPN( 10, ALL('Orange'),[Sales], DESC ),VALUES('Orange))

 

Hi @Anonymous 

Ensure that the 'Dimension' table and the measures referenced in the SWITCH function are properly defined in your Power BI data model.

This DAX expression checks the selected value of the 'Dimension Fields' column and returns the corresponding calculation based on the selected dimension.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Anonymous
Not applicable

@rajendraongole1  Thank you..I checked the field mappings are correct

GallopPBI_0-1716984379946.png

 

However, not sure why I see the composite key issue. Thanks

rajendraongole1
Super User
Super User

Hi @Anonymous - Small adjustment in SWITCH function to properly handle the selection of dimension fields and return the corresponding calculation

 

SWITCH TOP10 =
SWITCH(
SELECTEDVALUE('Dimension'[Dimension Fields]),
"Orange", CALCULATE([Top 10 - Orange]),
"Apple", CALCULATE([Top 10 - Apple]),
"Grapes", CALCULATE([Top 10 - Grapes]),
"Pineapple", CALCULATE([Top 10 - Pineapple]),
"Avocado", CALCULATE([Top 10 - Avocado]),
BLANK() -- Default value if none of the conditions are met
)

 

Try the above and let know

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Users online (4,217)