Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

SWITCH function with result TEXT

Hello all,

 

I have something pretty simple i guess, but i can not figure this out how with DAX.

I am looking for a result "Yes"or "No" as text.

 

On TimeCorrectionResult
YesYesYes
YesemptyYes
emptyemptyempty

 

 

 

Already tried this with the "IF"/"AND" function and the "SWITCH" function like this.

Result = switch(true(),Tbl[On Time]="Ja","Ja",Tbl[On Time]="","",Tbl[On Time]="Nee" && Tbl[Correction]="Ja","Ja")

 

The error i become is:

DAX comparison operations do not support comparing values of type True/False with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values.

 

I do not understand this error because i am not working with any True/False type.

Only with text("Yes"/"No" or an empty cell)

 

What do i miss?

 

 

Thank you.

 

Gr Alfons

 

6 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Sorry ,

     

    First On Time value in table has to be "No".

     

     

    Gr,

     

     

  • HotChilli's avatar
    HotChilli
    Community Champion

    Looks ok from here so you'll have to debug at your side.  Presumably it's the 3rd clause causing problems.  You can comment it out to test.

    Have you definitely got && as the logical 'and'?  Maybe you could test with e.g. 

    Result2 = switch(true,
    Tbl[On Time]="Yes", "Yes",
    Tbl[On Time]="", "",
    AND(Tbl[On Time]="No", 1), "Yes")  to see if you can get past the error
    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello HotChilli,

       

      Thanks,

       

      But unfortunately, i can not solve it.

      I tried it with your proposal.

      Result = Switch(TRUE(,

      Tbl[On Time]="Ja","Ja",

      Tbl[On Time]="","",

      AND(Tbl[On Time ]="Ja",Tbl[Correction]="Ja"),"")

       

      Error:

      DAX comparison operations do not support comparing values of type True/False with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values.

       

      If i am leaving the last part of the formula from the "AND" function away, it works find.

      But of couse misses the last part.

      So is has something to do something with this combined conditions.

       

      Do you have other options?

       

      Gr

  • FrankAT's avatar
    FrankAT
    Community Champion

    Hi Anonymous ,

    you can do it like this:

     

     

     

     

    Result = SWITCH(TRUE(),
        MIN('Tbl'[On Time]) = "Ja", "Ja",
        MIN('Tbl'[On Time]) = " ", " ",
        MIN('Tbl'[On Time]) = "Nee" && MIN('Tbl'[Correction]) = "Ja", "Ja"
    )

     

    With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
    FrankAT (Proud to be a Datanaut)

  • v-janeyg-msft's avatar
    v-janeyg-msft
    Community Support

    Hi, Anonymous 

     

    Is your problem been solved? Have you checked the data and data type of the Tbl[Correction] column in PQ?

     

    Best Regards

    Janey Guo

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.