Forum Discussion

vincentakatoh's avatar
vincentakatoh
Helper IV
8 years ago
Solved

DAX: IF, Filter, Datesbetween

Hi, 

 

Trying to add new column such that

IF datesbetween (2017,9,11), (2017,9,15)= "Proto1"

IF datesbetween (2017,9,18), (2017,9,22)= "Proto2"

IF datesbetween (2017,9,25), (2017,9,29)= "Proto3"

otherwise "null"

 

Can advice how can i write above in DAX? Should I be using IF or Filters?

  • Hi vincentakatoh,

     

    Try the following formula:

     

    Proto =
    SWITCH (
        TRUE (),
        'Calendar'[Date] >= DATE ( 2017, 9, 11 )
            && 'Calendar'[Date] <= DATE ( 2017, 9, 15 ), "Proto1",
        'Calendar'[Date] >= DATE ( 2017, 9, 18 )
            && 'Calendar'[Date] <= DATE ( 2017, 9, 22 ), "Proto2",
        'Calendar'[Date] >= DATE ( 2017, 9, 25 )
            && 'Calendar'[Date] <= DATE ( 2017, 9, 29 ), "Proto3",
        BLANK ()
    )

    Regards,

    MFelix

2 Replies

  • Hi vincentakatoh,

     

    Try the following formula:

     

    Proto =
    SWITCH (
        TRUE (),
        'Calendar'[Date] >= DATE ( 2017, 9, 11 )
            && 'Calendar'[Date] <= DATE ( 2017, 9, 15 ), "Proto1",
        'Calendar'[Date] >= DATE ( 2017, 9, 18 )
            && 'Calendar'[Date] <= DATE ( 2017, 9, 22 ), "Proto2",
        'Calendar'[Date] >= DATE ( 2017, 9, 25 )
            && 'Calendar'[Date] <= DATE ( 2017, 9, 29 ), "Proto3",
        BLANK ()
    )

    Regards,

    MFelix

    • vincentakatoh's avatar
      vincentakatoh
      Helper IV

      MFelix

      Works great. Thanks for introducing the "SWITCH" function. very useful function indeed. 

       

      Rgds, Vincent