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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anna_O
Frequent Visitor

SWITCH does not add the third value

Hello all,

 

I have a table of Course dates with columns Order Date, Sales Amount, etc. for purchasing other products before or after a course. I calculated a Date Difference between [Course Date] and [Order Date] in a separate column using DATEDIFF.

Now I want to attribute sales after the course to that course if the sale has happened not later than 90 days after the course, otherwise, I have different conditions.

I have this formula:

 

AfterSale = SWITCH(TRUE(),
AND([DateDiff]=0,[DateDiff]<=90),"After Course Sale",
AND([DateDiff]<0,[DateDiff]>=-90),"Before Course Sale",
[DateDiff]>-90,"Old Sales",
[DateDiff]>90,"Not Related")
 
I have two issues with this formula:
1. for some reason, Sales that happened between 0 and 90 days are attributed as "old Sales";
2. negative values are not attributed at all, I got blank cells.
 
Also, I can't include Value3. I don't know why, after Result2 in the formula I am only suggested to add Result3, but I want ti Have Value3 instead.
I want the formula to have 4 conditions (4 Values and 4 related Results).
 
What do I do wrong?
1 ACCEPTED SOLUTION
MattAllington
Community Champion
Community Champion

This is what I see. 
the first condition says "give me all results that are zero, and at the same time are less than 90".  This will return no result as there is no number that can be both. 
the second, third conditions have cross over. Eg -45 satisfies both 2 and 3. 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

View solution in original post

2 REPLIES 2
Anna_O
Frequent Visitor

Of course! Thanks for pointing this to me, I need more sleep, haha.

MattAllington
Community Champion
Community Champion

This is what I see. 
the first condition says "give me all results that are zero, and at the same time are less than 90".  This will return no result as there is no number that can be both. 
the second, third conditions have cross over. Eg -45 satisfies both 2 and 3. 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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