Forum Discussion

Pricey79's avatar
Pricey79
Icon for Helper V rankHelper V
3 years ago

Using two columns in Switch Function

Hello, I was hoping someone could help me please

 

I have a Switch function something like this :


'Mytable'[Stuff] = "ddd" , "Dave" ,
'Mytable'[Stuff] = "sss" , "Sarah" ,
'Mytable'[Stuff] = "kkn" , "Kev" ,
'Mytable'[Stuff] = "mll" , "Mo" ,
'Mytable'[Substuff] = "DIV, "VLAD",
'Mytable'[Substuff] = "DIVsss", "VLAD",
'Mytable'[Substuff] = "DIVmll", "VLAD",

 

I want to be able to say that if a row in substuff contains mll for example and a row in stuff contains mll , then switch to VLAD

 

How would I do that please? At the moment its only taking the argument from the Stuff column

 

Thank you

 

4 Replies

  • Alf94's avatar
    Alf94
    Icon for Solution Supplier rankSolution Supplier

    Hi Pricey79 ,

     

    I think you could use the AND() function. Try someting like the following measure:

     

    Measure =
      SWITCH(
        TRUE(),
        AND( Mytable[Stuff] = "mll", Mytable[SubStuff] = "DIVmll" ), "VLAD",
        AND( Mytable[Stuff] = "sss", Mytable[SubStuff] = "DIVsss" ), "VLAD"
      )

     

    If I answered your question, please mark my post as a solution.

     

    Best,

    • Pricey79's avatar
      Pricey79
      Icon for Helper V rankHelper V

      Alf94 thank you for taking the time to reply.

      Just to check , Can I carry on the rest of the switch with normal conditions? For example, if my table[stuff] equals mll but [substuff] doesnt, then switch mll to something else?

      • Alf94's avatar
        Alf94
        Icon for Solution Supplier rankSolution Supplier

        Pricey79I am not sure what you mean by "switch mll to something else".

         

        You can write different types of conditions in your switch statement:

         

        Measure =
          SWITCH(
            TRUE(),
            AND( Mytable[Stuff] = "mll", Mytable[SubStuff] = "DIVmll" ), "VLAD 1",
            AND( Mytable[Stuff] = "sss", Mytable[SubStuff] = "DIVsss" ), "VLAD 1",
            Mytable[Stuff] = "mll", "VLAD 2",
            AND( Mytable[Stuff] = "mll", Mytable[SubStuff] <> "mll" ), "VLAD 3",
            OR( Mytable[Stuff] = "ddd", Mytable[Substuff] = "DIVddd" ), "VLAD 4"
          )

        where the "<>" symbol means "not equal".

         

        Let me know if this answers your question.