Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Function 'SWITCH' does not support comparing values of type True/False with values of type Date.

Hello all,

I am trying to create a condition in DAX using a String and the same time a date range.
But I got this error: Function 'SWITCH' does not support comparing values of type True/False with values of type Date. 

Any ideas?

course length 1 = IF ('TOTAL'[Graduation Institution]="TAFE SA",
SWITCH(TRUE(),
DATESBETWEEN('TOTAL'[Orig Policy Start Date], DATE(2015,01,01), DATE(2015,06,30)),1,
0),0)

 

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Anonymous ,

     

    Datesbetween() returns a single-column date table. The formula cannot be compared with a table using Boolean values, so an error is reported.

    DATESBETWEEN

     

    I guess what you want to find is to match the rows of 'TOTAL' [Orig Policy Start Date] that meet between DATE(2015,01,01) and DATE(2015,06,30). Please try this:

    course length 1 =
    IF (
        'TOTAL'[Graduation Institution] = "TAFE SA",
        IF (
            MAX ( 'TOTAL'[Orig Policy Start Date] ) >= DATE ( 2015, 01, 01 )
                && MAX ( 'TOTAL'[Orig Policy Start Date] ) <= DATE ( 2015, 06, 30 ),
            1,
            0
        ),
        0
    )

     

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly -- How to provide sample data

5 Replies

  • Hi,

    The second input of the SWICH() function should result in a TRUE()/FALSE() expression.  That is not happening in our formula.  Describe the question and share some sample dataset.

    • Anonymous's avatar
      Anonymous
      Not applicable

      I wanna filter by date range and also include a string, so I can categorise those in that filter.

       

      • Ashish_Mathur's avatar
        Ashish_Mathur
        Icon for Super User rankSuper User

        Hi,

        I still do not understand.  Share some data and show the expected result.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    Datesbetween() returns a single-column date table. The formula cannot be compared with a table using Boolean values, so an error is reported.

    DATESBETWEEN

     

    I guess what you want to find is to match the rows of 'TOTAL' [Orig Policy Start Date] that meet between DATE(2015,01,01) and DATE(2015,06,30). Please try this:

    course length 1 =
    IF (
        'TOTAL'[Graduation Institution] = "TAFE SA",
        IF (
            MAX ( 'TOTAL'[Orig Policy Start Date] ) >= DATE ( 2015, 01, 01 )
                && MAX ( 'TOTAL'[Orig Policy Start Date] ) <= DATE ( 2015, 06, 30 ),
            1,
            0
        ),
        0
    )

     

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly -- How to provide sample data

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    Any update?😃

     

    Best Regards,
    Gao

    Community Support Team