Forum Discussion

bonnie's avatar
bonnie
Advocate I
8 years ago

Dax Switch for Legend not Measure

I'm trying to recreate something in Power BI I was easily able to do in Tableau.

I would like to have a selector that lets the user decide if they wish the color of the legend to be by department, division or job family. I created a View by Table with those 3 options and a selector from that table.

 

When  I try to create a calculated column wiht the switch function, it parses but never changes on change to the selector.  The value of the field remains to the 1st in the selection.

View = switch(FIRSTNONBLANK(Viewby[Viewby],Viewby[Viewby]),"Job Family",Employement[Job Family],"Department",Employement[Department],"Division",Employement[Division])

 

Any ideas would be great.

 

Thanks.

3 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    Would love to see some sample data and example of expected output.

  • v-yulgu-msft's avatar
    v-yulgu-msft
    Microsoft Employee

    Hi bonnie,

     

    Calculated column values won't be changed dynamically based on slicer selection as its values are initialized since created. Chart legend only supports column filelds, we are not able to add a measure into it.

     

    As of now, it is not possible to use slicer to change legend dynamically by checking column names. But you could try the workaround to create drill down report.

     

    Best regards,

    Yuliana Gu

    • PaulDBrown's avatar
      PaulDBrown
      Community Champion

      I'm not completely sure what exactly you are trying to achieve, and what visual you have in mind, but if you are trying to change an element of the visual or indeed  the type of visual to be displayed depending on a 'selection', a roundabout way of doing this is to use bookmarks, the visual selection pane and "toggle buttons" (instead of a slicer). You replicate or create three visual (one for each 'Employment[.....] value,  overlay them, add three "images" or buttons with the corresponding 'Employment' value, and use the bookmark and selection pane to hide and show the different visuals using the "toggle"-like behaviour (which is actually just using bookmarks and the selection pane). The user can then click on the button and the relevant visual is revealed.

       

      Not sure if that helps (my knowledge of Power BI is somewhat limited), but at least that is how I would go about doing it.

       

      EDIT: having re-read your message, I agree with Greg_Deckler. Please provide an example of what you are trying to achieve!