Forum Discussion
Tableau flag code translation?
- 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
Hi k3rz0rg ,
I’d like to acknowledge the valuable input provided by the OwenAuger . His initial ideas were instrumental in guiding my approach. However, I noticed that further details were needed to fully understand the issue.
In my investigation, I took the following steps:
I create a table as you mentioned.
Then I change your DAX code and get what you want.
Column =
IF (
'NA Pharmacy Distribution'[Sale_Code] = "D"
|| (
'NA Pharmacy Distribution'[Sale_Code] = "C"
&& NOT ISBLANK ( 'NA Pharmacy Distribution'[Contract_ID] )
&& 'NA Pharmacy Distribution'[Contract_ID] <> ""
),
1,
0
)
Best Regards
Yilong Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.