Forum Discussion

AU555's avatar
AU555
Helper I
6 years ago
Solved

Using switch in M

Hi all, I have an easy problem, but as I am a beginner i M I have a bit proglem with this. I have the following calculation in dax swithing between several dates. However, I need to make the same ca...
  • AlB's avatar
    6 years ago

    Hi AU555,

    you can try something like this, try adding a custom column with the following code

     

    if [C1] = null then [C1_1]

    else

       if [C2] = null then [C2_1]

    else

      if [C3] = null then [C3_1]

      else [C4]

     

    This would be equivalent to the following. IUse this pattern to build exactly what you need 

     

    ColumnName = SWITCH(

    TRUE();

    'table1'[C1]<> BLANK(); 'table1'[C1_1];

    'table1'[C2] <> BLANK(); 'table1'[C2_1];

    'table1'[C3]<> BLANK(); 'table1'[C3_1];

    'table1'[C4])

     

     

    Please mark the question solved when done and consider giving kudos if posts are helpful.

     

    Cheers  Datanaut

    
    

     

  • AlB's avatar
    AlB
    6 years ago

    AU555 

    You're right. Make it <> null in all cases instead of    = null

     

    Please mark the question solved when done and consider giving kudos if posts are helpful.

    Cheers  Datanaut