Skip to main content

Power BI

Needs Votes

Conditional formatted measures using SWITCH

Vote (3436) Share
Matt Allington's profile image

Matt Allington on 16 Jul 2016 04:20:35

A current limitation in Power BI SWITCH measures (and all Power Pivot actually) is that a SWITCH measure must have a single format. It is currently not possible to conditionally format the measure result based on any criteria - it is one single format only. There are valid use cases where you may want to change the format of the SWITCH measure depending on the result. Consider the following SWITCH statement
myMeasure = SUMX(MeasureTable,switch([selected measure],
1,[Total Sales],
2,[Total Cost],
3,[Total Margin],
4,[Chg Sales vs LY %]
))
The first 3 results are all currency format, but the last result is a percentage format. This currently can't be controlled. I would like to see an optional 3rd parameter in the SWITCH statement to set an alternate number format.

Administrator on 20 Aug 2020 01:22:10

From the comments and scenarios everyone's describing, the problem is really that you need a way to allow end-users to change which measure is displayed in a visual on the fly. As a few folks have mentioned, the FORMAT function might help in the interim, as long as you're showing the results in text rather than a chart. https://docs.microsoft.com/en-us/dax/format-function-dax has details on how to use that. The expression-based formatting feature that we've started work on may help to a certain extent, but that's really designed to change a visual's properties rather than the data type or format. We'll look into extending that work to support this scenario as well. We're moving this to Backlog status - our core plan is to build ways that end-users can change the dimensions or measures that are visible in a chart on the fly. They'll be able to explore much more freely rather than relying on the author to have set up complex expressions to control what's available. We'll update with more details as they're available.

Comments (70)
Matt Allington's profile image Profile Picture

Neelima Putrevu on 09 Mar 2023 08:30:03

RE: Conditional formatted measures using SWITCH

Matt Allington's profile image Profile Picture

Neelima Putrevu on 09 Mar 2023 08:25:33

RE: Conditional formatted measures using SWITCH

Matt Allington's profile image Profile Picture

92650b9d b1f1-ea11-a815-000d3a9b112e on 08 Sep 2020 10:31:20

RE: Conditional formatted measures using SWITCH

Hi - this can now be done although it is a bit complex and has some limits.

Check my post here:
https://community.powerbi.com/t5/Desktop/Dynamic-formatting-of-measures-tutorial/m-p/1297373#M565099

Matt Allington's profile image Profile Picture

40072875 0b78-476d-82a5-7e8c035d3462 on 16 Aug 2020 04:19:23

RE: Conditional formatted measures using SWITCH

needed thanks

Matt Allington's profile image Profile Picture

11874a8b a1e8-4d76-bc1f-4d6caadb7a37 on 16 Aug 2020 04:19:23

RE: Conditional formatted measures using SWITCH

We need this feature in financial reports! Users have to be able to switch to actual values and values in thousands.

Matt Allington's profile image Profile Picture

02d912eb 01cd-49db-bbf5-7c8fd34a8fc2 on 16 Aug 2020 04:19:22

RE: Conditional formatted measures using SWITCH

In Excel, you can change the format of a y-axis on a graph or the values of a pivot table value independently of the underlying source data. So similarly to being able to adjust the Display Units and decimal places of the labels and/or axis of a given visual you should also be able to edit the format independent of the underlying measure or column. Further to address this idea, you could allow expressions on this similar to titles which would solve the problem that we are having.

This would allow the underlying measure or column to remain as a number as opposed to text and therefore it would be "graphable" and then the graph or visual axis/label formatting could handle how it is displayed in terms of the format.

Update: looks like they are solving this with calculation groups, but i still like the idea above which would be an agile option for end users.

Matt Allington's profile image Profile Picture

3f0113d6 f5f4-4426-b95f-940aad46902f on 16 Aug 2020 04:19:21

RE: Conditional formatted measures using SWITCH

myMeasure = SUMX(MeasureTable,switch([selected measure],
1,{[Total Sales], type currency},
2,{[Total Cost], type currency},
3,{[Total Margin], Percentage.Type},
4,{[Chg Sales vs LY %], Percentage.Type}
))

Matt Allington's profile image Profile Picture

7af09c6c 9d46-4cea-a50b-5b54be6b0986 on 16 Aug 2020 04:19:17

RE: Conditional formatted measures using SWITCH

Please implement this idea. Would make our financial reporting much easier.

Matt Allington's profile image Profile Picture

da8c22b4 2ed5-4293-9ff4-94ac0d77ccfb on 16 Aug 2020 04:18:10

RE: Conditional formatted measures using SWITCH

My view is that this would be solved if the FORMAT function had Left, Center and Right alignment and padding. Maybe this would be simpler?

Matt Allington's profile image Profile Picture

2c31f9f0 abdc-4598-9173-df7ad4a579eb on 16 Aug 2020 04:17:33

RE: Conditional formatted measures using SWITCH

Still waiting for this to be implemented, this is a bummer for people who have to create financial reports that have different measures with different data types when using slicer measures