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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Anonymous
Not applicable

SWITCH ( TRUE() ) with multiple criteria?

I'm trying to perform a calculation that will render costs charged by multiple vendors across multiple products and then get a grand total. Maybe I'm trying to do too much up front, but here's where I'm at so far. Table A is Vendor, and I'm trying to do calculations either in a statement or another table. Sorry for the mess in advance. Trying to figure out how to make it all work. 

 

Vendor A charges 4 different amounts based on threshold: 

Vendor

product

amountthreshold
jimapples.10<20
jimapples.09>=21 & < 40
jimapples.08>= 41 & < 60
jimapples.07>61
jimoranges.10<20
jimoranges.09>=21 & < 40
jimoranges.08>= 41 & < 60
jimoranges.07>61

 

There are 2 vendors that have different prices for the 2 products and 3 vendors that have a combined rate. All vendors have different thresholds and prices. I've been trying to write a Switch ( True () ) measure to solve this, but am not having much luck. here's my attempt at getting this to work for a single vendor. After I've done that, I'll expand the statement to work for the rest. 

 

 

Vendor PPM =
VAR jimApples_300k = 0.4070
VAR JimOranges_300k = 0.3960
VAR JimApples_900k = 0.3060
VAR JimOranges_900k = 0.3100

return
SWITCH( TRUE(),
CALCULATE('Vendor'[Vendor Billable] >= 300000,
'vendor'[VENDORNAME] = "jim",
'Vendor '[VENDORNAME] ="jim"),
'Vendor '[Vendor Billable]*jimApples_300k,
'Vendor '[Vendor Billable] >300000 && 'Vendor'[Vendor Billable] <=900000, 'Vendor'[Vendor Billable] * jimApple_900k,
'Vendor Call Data'[Vendor Billable]
 
First, will switch(true()) work? Second, if not, does anyone have another idea of how to set this up?
1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@aharon0414 - I usually do not see calculate statements in a SWITCH(TRUE()...) statement. SWITCH is usually like:

SWITCH(TRUE(),
  'Vendor'[VENDORNAME] = "jim" && 'Vendor'[Vendor Billable] > 300000, <some calc>,
  'Vendor'[VENDORNAME] = "jim" && 'Vendor'[Vendor Billable] > 150000, <some calc>,
  <some calc>
)


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@Anonymous , Switch true will work but i doubt syntax you use refer example

 

Switch([age_group]
, "AgeGRoup_0-4" , 1
, "AgeGroup_5-9" , 2
, "AgegRoup_10-14" ,3
, "AgegRoup_15-19" , 4
, "AgegRoup_20-24" , 5
, "AgegRoup_25-29" , 6

7
)

or

Switch([age_group]
, "AgeGRoup_0-4" && [ABC] =4 || [def] =4 , 1
, "AgeGroup_5-9" , 2
, "AgegRoup_10-14" ,3
, "AgegRoup_15-19" , 4
, "AgegRoup_20-24" , 5
, "AgegRoup_25-29" , 6

7
)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Greg_Deckler
Community Champion
Community Champion

@aharon0414 - I usually do not see calculate statements in a SWITCH(TRUE()...) statement. SWITCH is usually like:

SWITCH(TRUE(),
  'Vendor'[VENDORNAME] = "jim" && 'Vendor'[Vendor Billable] > 300000, <some calc>,
  'Vendor'[VENDORNAME] = "jim" && 'Vendor'[Vendor Billable] > 150000, <some calc>,
  <some calc>
)


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thank you @Greg_Deckler !

That seemed to get me a step forward. SWITCH (True) ) is working now, but in my variables, it will only calculate based on the first variables created. My variables all reference another variable that transitions the context between respective vendors, but that is not carrying forward in the totality of the SWITCH statement. I'll try to work up a mockup to share, but for now, my data is confidential and it may be a lot of work to put something together. 

@Anonymous it can be easily achieved by measures, if you put sample data in pbix file, it will help and I don't think SWITCH is the answer here, I could be totally wrong.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors