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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
schwinnen
Helper V
Helper V

Switch function between two values

I need to put some values into buckets.  I believe the switch function is the way to go, but I'm not sure how it works when I need one of the criteria to fall in between two values.  This is what I need my formula to do:

 

TIME AT FINAL = SWITCH (
TRUE (),
'QA'[AVG TIME AT DESTINATION] <75,"0-75",
'QA'[AVG TIME AT DESTINATION] >75<105,"75-105"

'QA'[AVG TIME AT DESTINATION] >105,">105"
)

 

The middle part of the formula says that if AVG TIME AT DESTINATION is between 75-105, make the value "75-105".  However, this does not work with the Switch function, at least not how I have it written.  How would I accomplish this?

Thanks in advance for your help.

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

Two possible ways to do this:

 

TIME AT FINAL = SWITCH (
TRUE (),
'QA'[AVG TIME AT DESTINATION] <75,"0-75",
'QA'[AVG TIME AT DESTINATION] >75 && 'QA'[AVG TIME AT DESTINATION]<105,"75-105"
'QA'[AVG TIME AT DESTINATION] >105,">105"
)


or

TIME AT FINAL = SWITCH (
TRUE (),
'QA'[AVG TIME AT DESTINATION] <75,"0-75",
''QA'[AVG TIME AT DESTINATION] >105,">105",
"75-105"
)


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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

Two possible ways to do this:

 

TIME AT FINAL = SWITCH (
TRUE (),
'QA'[AVG TIME AT DESTINATION] <75,"0-75",
'QA'[AVG TIME AT DESTINATION] >75 && 'QA'[AVG TIME AT DESTINATION]<105,"75-105"
'QA'[AVG TIME AT DESTINATION] >105,">105"
)


or

TIME AT FINAL = SWITCH (
TRUE (),
'QA'[AVG TIME AT DESTINATION] <75,"0-75",
''QA'[AVG TIME AT DESTINATION] >105,">105",
"75-105"
)


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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Nice, @Greg_Deckler

For future reference, is the a reason that there needs to be two && in the formula?  Does that have a meaning?

&& is your logical AND filter construct shorthand. A single & is concatenation. You could have used the AND function as well. || is OR.



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

I'd suggest you might want to assign a variable here.

TIME AT FINAL =
Var avgtime = QA[AVG TIME AT DESTINATION]
RETURN
SWITCH (
   TRUE ()
   , avgtime <75,"0-75"
   , avgtime >105,">105"
   , "75-105"

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.