Forum Discussion

DRJ1994's avatar
DRJ1994
Helper I
4 years ago
Solved

Help with SWITCH Statement

Hi guys, 

Hope you can help. I am trying to use a switch statement to create categories labeled as "0-7 days" "8-30 days" and"30+ days".

However I keep recieving the following error code:

 

"DAX Comparison operations do not support comparing values of type true/false with values of type integer. Consider using the VALUE or FORMAT function to convert one of the values".

I have attached a screenshot of the DAX and error message below:

I have checked the 'Days' Data type and it is formatted as a number. Any idea where I am going wrong and how to fix it?

 

Thanks in advance!

DRJ.

  • Hi DRJ1994 ,

     

    Please try this:-

     

    length of sickness =
    SWITCH (
        TRUE (),
        'Sheet1 (2)'[Days] <= 7, "0-7 days",
        'Sheet1 (2)'[Days] >= 8
            && 'Sheet1 (2)'[Days] <= 30, "8-30 days",
        'Sheet1 (2)'[Days] > 30, "30+ days"
    )
    

     

     

    BR,

    Samarth

2 Replies

  • Samarth_18's avatar
    Samarth_18
    Community Champion

    Hi DRJ1994 ,

     

    Please try this:-

     

    length of sickness =
    SWITCH (
        TRUE (),
        'Sheet1 (2)'[Days] <= 7, "0-7 days",
        'Sheet1 (2)'[Days] >= 8
            && 'Sheet1 (2)'[Days] <= 30, "8-30 days",
        'Sheet1 (2)'[Days] > 30, "30+ days"
    )
    

     

     

    BR,

    Samarth

    • DRJ1994's avatar
      DRJ1994
      Helper I

      Thank you so much! That helped and solved my issue!