Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

Error in DAX?

I have written this formula as a part of custom column:

 

if[GRP]="3" then "Contract" else if[GRP]="4" then Contract" else if[GRP]="6" then "Contract" else if[GRP]="7" then "Contract" else if[GRP]="9" then "Contract" else if[GRP]="2" then "Contract" else if([GRP]="B" and [JOB] <> 12345) then "Contract" else "Regular Employee"

 

I executed the same for another table and it worked but whenn I create the same for another table and check for else if([GRP]="ZY" and [JOB] <> 12345) then "Contract" with filters it does not show regular for the job = 12345.

 

Any idea as to why this could happen? Because, it gets executed perfectly in another table. Basically if GRP=B and JOB is not equal to 12345 then it is under contract else, regular. But when I filter for GRP=B and JOB=12345 it still comes under contract for me. 

 

  • Anonymous's avatar
    Anonymous
    8 years ago

    Hey, I tried the same code again with the text instead of code and it worked

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    HI Anonymous,

     

    According to your description, I think your formula is m query instead of dax formula.

     

    You can try to use below formula if it sutiable for your scenario.

     

    M query formula:

    #"Added Custom" = Table.AddColumn(#"Preview step", "Custom column", each if List.Contains({"2","3","4","6","7","9"},[GRP]) or ([GRP]="B" and [JOB] <> 12345) then "Contract" else "Regular Employee")

     

    Dax formule:

    Dax formula=
    IF (
        OR (
            [GRP] IN { "3", "4", "6", "7", "9", "2" },
            AND ( [GRP] = "B", [JOB] <> 12345 )
        ),
        "Contract",
        "Regular Employee"
    )
    

    Regards,

    Xiaoxin Sheng

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hey, I tried the same code again with the text instead of code and it worked