Forum Discussion

Maximous89's avatar
Maximous89
Helper I
1 year ago
Solved

DAX Switch & nested IF

https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-challenge-nested-if-or-switch-is-not-working/m-p/4792912#M183444

 

i can't belive there is no solution for this,

 i need a simple dax measure 

IF( ISINSCOPE( HIER[LEVEL_7_DESC] ), 17, IF( ISINSCOPE( HIER[LEVEL_6_DESC] ), 16, IF( ISINSCOPE( HIER[LEVEL_5_DESC] ), 15 ) ) )

 

this doesn't work because if i change the order of column in the visual then the higher or the first condtition will always be the only one is true returning this value only?!!

 

 

 

  • Maximous89 

     

    Weird when you say 'i can't belive there is no support on this'.. I clicked open your original post and saw Community support followed up twice on your question there. 

  • I left a comment on your original post, but here it is agian: 

    Realistically, a field parameter would be a better implementation of this situation than a DAX Switch statement. For the field parameter, you would select/add every measure you would like a user to select from (like what you have in the switch statement) and use this as a slicer on the page. Also with a field parameter, you can select multiple values and each value will appear and not get ignored like a Switch statement would. 

    To add onto this, if you need the ability for end-users to select multiple data elements a field parameter would be a better solution than nested IF's or Switch statements. Here's the documentation for field parameters: Use report readers to change visuals - Power BI | Microsoft Learn

8 Replies

  • Maximous89 

     

    Weird when you say 'i can't belive there is no support on this'.. I clicked open your original post and saw Community support followed up twice on your question there. 

  • Hi Maximous89 

     

    You could use a measure that checks which level has a non-blank value, assuming each level is only populated when it's relevant:

    LevelNumber = 
    SWITCH(
        TRUE(),
        NOT(ISBLANK(SELECTEDVALUE(HIER[LEVEL_7_DESC]))), 17,
        NOT(ISBLANK(SELECTEDVALUE(HIER[LEVEL_6_DESC]))), 16,
        NOT(ISBLANK(SELECTEDVALUE(HIER[LEVEL_5_DESC]))), 15,
        BLANK()
    )

     

    I hope this helps

  • hi Maximous89 ,

    Please share some sample data and expected output to understand the ask. sometimes only looking at the DAX doesn't help but the entire scenario does.

  • v-hashadapu's avatar
    v-hashadapu
    Community Support

    Hi Maximous89 , Thank you for reaching out to the Microsoft Community Forum.

     

    As you haven't shared any data and it is very hard to provide a solution without it, I took some sample data based on your scenario and created a .pbix file with a working solution for you reference. Please check the attached .pbix file and share your thoughts.

     

    Thank you.

  • v-hashadapu's avatar
    v-hashadapu
    Community Support

    Hi Maximous89 , Hope you're doing fine. Can you confirm if the problem is solved or still persists? Sharing your details will help others in the community.

  • v-hashadapu's avatar
    v-hashadapu
    Community Support

    Hi Maximous89 , hope you are doing great. May we know if your issue is solved or if you are still experiencing difficulties. Please share the details as it will help the community, especially others with similar issues.

  • v-hashadapu's avatar
    v-hashadapu
    Community Support

    Hi Maximous89 , Hope you're doing okay! May we know if it worked for you, or are you still experiencing difficulties? Let us know — your feedback can really help others in the same situation.

  • I left a comment on your original post, but here it is agian: 

    Realistically, a field parameter would be a better implementation of this situation than a DAX Switch statement. For the field parameter, you would select/add every measure you would like a user to select from (like what you have in the switch statement) and use this as a slicer on the page. Also with a field parameter, you can select multiple values and each value will appear and not get ignored like a Switch statement would. 

    To add onto this, if you need the ability for end-users to select multiple data elements a field parameter would be a better solution than nested IF's or Switch statements. Here's the documentation for field parameters: Use report readers to change visuals - Power BI | Microsoft Learn