Forum Discussion

g-wizard's avatar
g-wizard
Frequent Visitor
2 years ago
Solved

DAX calculation-IF/AND/OR

Hello I am getting stuck on this calc that i had in tableau.

Could any support me in converting this to dax?

IIF(([Campaign Type]="ZKMT" AND [Cust Flag]="O") OR ([Campaign Type]="ZDDK" AND [Cust Flag]="O") OR ([Campaign Type]="ZMDK" AND [Cust Flag]="O") OR ([Campaign Type]="ZVDK" AND [Cust Flag]="O"),[CRM_CAMPAIGN_ID],NULL)

  • g-wizard ,

    Recommend using SWITCH Statement as follows:

     = SWITCH(
           TRUE(),
          AND( [Campaign Type]="ZKMT", Cust Flag]="O" ), [CRM_CAMPAIGN_ID],
          AND( [Campaign Type]="ZDDK", Cust Flag]="O" ), [CRM_CAMPAIGN_ID],
          AND( [Campaign Type]="ZMDK", Cust Flag]="O" ), [CRM_CAMPAIGN_ID],
          BLANK() )

    There are other ways this can be written, but I find this method keeps your conditions more clear and concise.

    Hope this helps.

    Regards,

4 Replies

  • rsbin's avatar
    rsbin
    Community Champion

    g-wizard ,

    Recommend using SWITCH Statement as follows:

     = SWITCH(
           TRUE(),
          AND( [Campaign Type]="ZKMT", Cust Flag]="O" ), [CRM_CAMPAIGN_ID],
          AND( [Campaign Type]="ZDDK", Cust Flag]="O" ), [CRM_CAMPAIGN_ID],
          AND( [Campaign Type]="ZMDK", Cust Flag]="O" ), [CRM_CAMPAIGN_ID],
          BLANK() )

    There are other ways this can be written, but I find this method keeps your conditions more clear and concise.

    Hope this helps.

    Regards,

    • g-wizard's avatar
      g-wizard
      Frequent Visitor

      Thank you so much for your support this makes complete sense!!

  • Hi g-wizard 

    Maybe try something like this.

     

    z =
    IF(
        [Cust Flag] = "O" 
    		&& [Campaign Type] IN { "ZKMT", "ZDDK", "ZDMK", "ZVDK" },
        [CRM_CAMPAIGN_ID]
    )