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
MrDatanaut
New Member

Conditional formatting a switch measure

Dear PBI Community! 

 

I have the following switch-measure which is used to show different financial and volume measures within one and the same visual.

 

What I am looking to do is have "(Selected) Value" be formatted with 2 decimals IF "volume" is selected from the dropdown and show no decimals if any other of the values is selected (Revenue, CM or GP).

 

Could you please help me accomplish this in the DAX below? 

 

(Selected) Value =

VAR Selection = SELECTEDVALUE('Dim_Measure_Selection_Master'[Value Types], "ALL" )

RETURN

 

SWITCH(true(),

Selection = "Volume", [Volume (MT)],

Selection = "Revenue", [Total Revenue ($)],

Selection = "Contribution Margin", [Total Contribution Margin ($)],

Selection = "Gross Profit", [Total Gross Profit ($)],

[Total Contribution Margin ($)]

)

 

Thank you very much! 

1 ACCEPTED SOLUTION
jameszhang0805
Resolver IV
Resolver IV

Use the FORMAT function to get the result, but the best way is to use calculate group

jameszhang0805_0-1613744165446.png

jameszhang0805_1-1613744208184.png

 

View solution in original post

3 REPLIES 3
MrDatanaut
New Member

Thank you for the prompt reply! I tried this however get an error, will the Format function make my measure into text?

 

Error Message:
MdxScript(Model) (110, 1) Calculation error in measure '_Measure_Selection_Cycle'[(Selected) Value]: Cannot convert value '' of type Text to type Numeric/Date.

 

yes the return value type of format is string

jameszhang0805
Resolver IV
Resolver IV

Use the FORMAT function to get the result, but the best way is to use calculate group

jameszhang0805_0-1613744165446.png

jameszhang0805_1-1613744208184.png

 

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.