Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anmolgan
Post Prodigy
Post Prodigy

Mutliple If conditions in one column DAX?

I have mutiple conditions that I want to implement is one DAX formula, there can be multiple dax formulas for multiple conditions for now I have 8 conditions, I want to write this in such a way so that I place all the values by filtering out billing key, customer key and material key and values coming in the date periods (lets say 4APRIL 2019 to 1APRIL 2020) among the actual tables that I have. How can I build a custom columns using this?

2 REPLIES 2
d_gosbell
Super User
Super User

If all your columns are in the one table you can just combine the multiple filter conditions using the logical and ( && ) or the logical OR ( || ). So to filter for material key 123 AND customer 456 and dates between 4 April 2019 and 1 April 2020 you could do something like the following

 

= IF ( table[MaterialKey] = 123

  && table[CustomerKey] =  456
  && table[Date] >= DATE(2019,4,4)
  && table[Date] <= DATE(2020,4,1) ,
<result to return goes here> )

 

But your requirements are a little vauge so I'm not sure if I've understood them correctly. If not could you provide some example data and show the expected results to help illustrate a specifc example of the logic you are trying to apply?

Thanks for your answer below is what I have and what I need:

 

I have an excel with certain different conditions For Example

Document   Group    Value

ZBDC            11          0.5

ZBFI              22          0.5

ZBDC            33          1.0

Now my actual query where I will create my custom column looks like this

Document   Group      Volume
ZBDC           11             103.2

ZBDC            23            2000

For some Conditons is like whenever document and group matches take the Value as it is. In the same way I have another table like:

Document    Group      MaterialGroup    Value
ZBDC             11            06                       2.5
ZBDC             22             25                      1.2
ZBDS             21              blank                 1.2

For the above data I need to mutiply Value x Volume and put that inside my custom column, now both the dataset that are not highlighted are in the same table, how can I write the queries to pick values directly from one table and apply my condition, the way that I am doing here is manually entering the values inside my different columns for each conditions and sum all of those and divide by another field and subtract the outcome from another field and use that in my report. below is a small example of one of my DAX queries:

Unnati + MLP (Z190) = SWITCH(
TRUE(),
[Billing Type.Billing Type Level 01.Key]= "ZBDC" && [Customer Group.Customer Group Level 01.Key]= "11" && [Material group.Material group Level 01.Key] = "25" && ZSD_Mat_Margin_Q003[Calendar Day.Calendar Day Level 01.Key]>= DATE(2019,04,01) && ZSD_Mat_Margin_Q003[Calendar Day.Calendar Day Level 01.Key]<= DATE(2020,03,31), "2.75" * [Volume],
[Billing Type.Billing Type Level 01.Key]= "ZBDC" && [Customer Group.Customer Group Level 01.Key]= "12" && [Material group.Material group Level 01.Key] = "25" && ZSD_Mat_Margin_Q003[Calendar Day.Calendar Day Level 01.Key]>= DATE(2019,04,01) && ZSD_Mat_Margin_Q003[Calendar Day.Calendar Day Level 01.Key]<= DATE(2020,03,31), "2.75" * [Volume])


Warranty Claims Z110 = SWITCH(
TRUE(),
[Billing Type.Billing Type Level 01.Key]= "ZBDC" && [Billing Type.Billing Type Level 01.Key]= "ZBF2" && [Customer Group.Customer Group Level 01.Key]= "14" && [Material group.Material group Level 01.Key] = "06" && ZSD_Mat_Margin_Q003[Calendar Day.Calendar Day Level 01.Key]>= DATE(2019,04,01) && ZSD_Mat_Margin_Q003[Calendar Day.Calendar Day Level 01.Key]<= DATE(2020,03,31), "28",
[Billing Type.Billing Type Level 01.Key]= "ZBDS" && [Customer Group.Customer Group Level 01.Key]= "14" && [Material group.Material group Level 01.Key] = "06" && ZSD_Mat_Margin_Q003[Calendar Day.Calendar Day Level 01.Key]>= DATE(2019,04,01) && ZSD_Mat_Margin_Q003[Calendar Day.Calendar Day Level 01.Key]<= DATE(2020,03,31), "28",
[Billing Type.Billing Type Level 01.Key]= "ZBFI" && [Customer Group.Customer Group Level 01.Key]= "14" && [Material group.Material group Level 01.Key] = "06" && ZSD_Mat_Margin_Q003[Calendar Day.Calendar Day Level 01.Key]>= DATE(2019,04,01) && ZSD_Mat_Margin_Q003[Calendar Day.Calendar Day Level 01.Key]<= DATE(2020,03,31), "28")


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.