Forum Discussion

patL's avatar
patL
New Member
10 months ago
Solved

Switch with compare Values Text

Hello - new to the community and new to DAX, i have something that up to line 4 works but how can i make line 5-6 to work?

 

Thanks,

 

 

 

  • hello patL 

     

    how about this (not sure if this will work since i dont test it out).

    TierBreakdown = 
    SWITCH(TRUE(),
    [Value]="D"&&([Value]="A"||[Value]="B"||[Value]="C"),"increased
    [Value]="C"&&([Value]="A"||[Value]="B"),"increased",
    [Value]="B"&&[Value]="A","increased"
    [Value]="A","decreased",
    "decreased"

    Basically SWITCH has same syntax as IF, the first line will be kicked first.

    I usually put the most specific statement so it will be kicked first.

     

    Also you need a statement then true value, while false statement will be placed at the very last.

     

    i think line 5-6 dont work because the value has been triggered by either line 3 or line 4.

     

    Hope this will help.

    Thank you.

4 Replies

  • hello patL 

     

    how about this (not sure if this will work since i dont test it out).

    TierBreakdown = 
    SWITCH(TRUE(),
    [Value]="D"&&([Value]="A"||[Value]="B"||[Value]="C"),"increased
    [Value]="C"&&([Value]="A"||[Value]="B"),"increased",
    [Value]="B"&&[Value]="A","increased"
    [Value]="A","decreased",
    "decreased"

    Basically SWITCH has same syntax as IF, the first line will be kicked first.

    I usually put the most specific statement so it will be kicked first.

     

    Also you need a statement then true value, while false statement will be placed at the very last.

     

    i think line 5-6 dont work because the value has been triggered by either line 3 or line 4.

     

    Hope this will help.

    Thank you.

  • Hi,

     

    it seems the reason its not working is, you cant have both false condition value for each check, you can have false condition value only at the end. The syntax of SWITCH is 

    SWITCH(<expression>, <value>, <result>[, <value>, <result>]…[, <else>])

    Hence at the end of line 4, when you have added "Increase", "Decrease" then it is failing. You can have only 1 ELSE condition at the end of all condition check.

     

    I created a dummy SWITCH to show multiple conditions are working

    Hope this helps to resolve your problem. If it does then please mark it as solution.

    Thanks - Samrat

  • patL 


    I think the problem is on the fourth line.

     

    only leave increase or decrease. You can't have two values.

     

  • Thankyou, samratpbiIrwanryan_mayu, for your responses.

    Hi patL,

    We appreciate your question on the Microsoft Fabric Community Forum.

    Based on my understanding, the SWITCH function expects pairs of (value, result). When we use SWITCH(TRUE(), <cond1>, <res1>, <cond2>, <res2>, ..., <else>), each condition must be followed by a single result. The screenshot indicates extra result tokens placed where SWITCH anticipated the next  <value> or condition, which causes the syntax error.

    Please find attached a screenshot and a sample PBIX file using SWITCH() that may assist in resolving the issue:



    We hope the information provided helps to resolve the matter. Should you have any further queries, please feel free to contact the Microsoft Fabric community.

    Thank you.