Forum Discussion

Lancelot's avatar
Lancelot
Frequent Visitor
3 years ago

Same values to two different conditions

Hi All

 

I have a situation where an Account is assigned two different descriptions as below:

When I run this code, power bi only populates the first condition depending on which one is at the top. In this case, Only Tax Liabilitites is populated when the Account is found. Any work arounds?

 

 if List.Contains({
"510100",
"750100"},[Account]) then "Tax Liabilities"
else if List.Contains({
"510100",
"750100"
},[Account]) then "Taxation Prepaid"

4 Replies

  • jaweher899's avatar
    jaweher899
    Icon for Impactful Individual rankImpactful Individual

    You can use the SWITCH statement in Power BI DAX to evaluate multiple conditions and return the corresponding value. Here is an example of how to implement the same in your case:

    = SWITCH([Account], "510100", "Tax Liabilities", "750100", "Tax Liabilities", "510100", "Taxation Prepaid", "750100", "Taxation Prepaid", BLANK() )

    This will return "Tax Liabilities" when the Account is 510100 or 750100, and "Taxation Prepaid" when it is also 510100 or 750100. If the Account value is not found in either list, it will return a blank value.

    • Lancelot's avatar
      Lancelot
      Frequent Visitor

      I already have multiple if statements for different accounts. I would like to not change the apporach to switch. Any other way using the if statements?

       

       

      • jaweher899's avatar
        jaweher899
        Icon for Impactful Individual rankImpactful Individual

        It looks like you are checking the same list of account codes in both conditions of the if statement, which would result in both conditions having the same outcome. To resolve this issue, you could modify your code to include different lists of account codes for each condition.

        Example:

        if List.Contains({"510100"}, [Account]) then "Tax Liabilities" else if List.Contains({"750100"}, [Account]) then "Taxation Prepaid"