DEV Community

Cover image for SWITCH SELECTION IN POWER BI DAX
John Kyalo
John Kyalo

Posted on

SWITCH SELECTION IN POWER BI DAX

After a sort of an hiatus, okay not really a planned one, I am here to talk about the switch selection in Power BI Dax.

Here is the scenario...
You have calculated many measures, and you want to know get to understand the %Achieved.
The approach would be first get the measure targets for all the measures you have then now subsequently do other measures with %Achieved whereby it's an %achieved = DIVIDE([achieved],[target])

Hold on, but that sounds a long route, and it is a traditional approach to providing solutions. What if I told you that we have a dynamic approach that could be done with a few steps?

Here are the steps:

  1. Get a disconnected table with all indicators that you are tracking.
  2. Establish a relationship of the table above with your targets table probably using the Indicator Id.
  3. Now proceed to only do a single measure of targets by establishing a variable of the selected Indicator. see example below:
    VAR SelInd = SELECTEDVALUE(disc[Indicator_id])
    RETURN
    CALCULATE(
    SUM(Targets[Target_value]),
    Targets[Indicator_id] = SelInd
    )

    The measure above basically looks for the indicator selected, and retrieves the target for that particular Indicator only (a dynamic approach)

  4. Now our many measures also need to be wired in a switch logic that matches the Indicator_id in the disconnected table.
    This way you only have one measure that contains all the achieved values of the indicators. It is this measure that we use to get to our %Achieved.
    Basically a switch based on selected value in disc table

  5. Now that you have your two measures, achievements and target, go ahead and calculate the %Achieved
    %Achieved = DIVIDE([Achieved], [Targets])

Voila, use the above in your visuals.

key:
The relationship between the disconnected table and the Targets table allows you to dynamically fetch the target values for the selected indicator.

The switch statement in the achieved measure dynamically calculates the achieved value based on the selected indicator.

Remember,
Anything and Everything Data

Top comments (0)