Forum Discussion

k3rz0rg's avatar
k3rz0rg
Advocate III
2 years ago
Solved

Tableau flag code translation?

Hi everyone,  I created a flag on tableau which works fine but now I have to translate that in DAX and I tried with if-else and it's throwing me error. Could you please help me with it? Tableau co...
  • OwenAuger's avatar
    2 years ago

    Hi k3rz0rg 

    It looks like you're creating a calculated column - is that right?

     

    I would suggest this. I've used variables for readability and you can use the && operator instead of the AND function to handle more than 2 conditions.

    Also, VALUES isn't needed if you are referring to a column's value in a row context (assuming this is a calculated column). Just use the column reference directly.

     

    Flag = 
    VAR SaleCode = 'NA Pharmacy Distribution'[Sale_Code]
    VAR ContractID = 'NA Pharmacy Distribution'[Contract_ID]
    RETURN
        IF (
            OR (
                SaleCode = "D",
                SaleCode = "C" && ContractID <> "" && NOT ( ISBLANK ( ContractID ) )
            ),
            1,
            0
        )

     

    Regards

  • k3rz0rg's avatar
    k3rz0rg
    2 years ago

    Hi OwenAuger , thank you for your response! I was trying to create a calculated measure and almost forgot that I could create a column as well since I'm the owner of the dataset. Your suggestion helped me to solved my purpose!