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

Shape the future of the Fabric Community! Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions. Take survey.

Reply
Anonymous
Not applicable

How to add text condition in Switch

dd

 

Hello - I need to add another condition to this statement, but not sure how.
 
I need to add: allopps-products[status]="open" as one of the conditions. But it won't let me.
 
What do I need to do to be able to add this condition?
 
SWITCH(
    TRUE(),
    MAX('AllOpps-Products'[Prob.]) = 80, "30 Days",
    DATEDIFF(MAX('AllOpps-Products'[Est.Ship]),TODAY(),DAY)> 90, "Older than 90",
    DATEDIFF(MAX('AllOpps-Products'[Est.Ship]),TODAY(),DAY)> 60, "Older than 60",
    DATEDIFF(MAX('AllOpps-Products'[Est.Ship]),TODAY(),DAY)> 30, "Older than 30",
    DATEDIFF(MAX('AllOpps-Products'[Est.Ship]),TODAY(),DAY)> 15, "30 Days",
    FALSE
)
1 ACCEPTED SOLUTION
Anonymous
Not applicable

@az38  I got it to work using this: 

 

TRUE(),
    DATEDIFF(MAX('AllOpps-Products'[Est.Ship]),TODAY(),DAY) > -1 &&  DATEDIFF(MAX('AllOpps-Products'[Est.Ship]),TODAY(),DAY) > -20, "Passed already"

View solution in original post

8 REPLIES 8
amitchandak
Super User
Super User

@Anonymous , not very clear where you want to use that. But check a couple of options

if(max(allopps-products[status])="open",
SWITCH(
    TRUE(),
    MAX('AllOpps-Products'[Prob.]) = 80, "30 Days",
    DATEDIFF(MAX('AllOpps-Products'[Est.Ship]),TODAY(),DAY)> 90, "Older than 90",
    DATEDIFF(MAX('AllOpps-Products'[Est.Ship]),TODAY(),DAY)> 60, "Older than 60",
    DATEDIFF(MAX('AllOpps-Products'[Est.Ship]),TODAY(),DAY)> 30, "Older than 30",
    DATEDIFF(MAX('AllOpps-Products'[Est.Ship]),TODAY(),DAY)> 15, "30 Days",
    FALSE
),blank())


SWITCH(
    TRUE(),
    MAX('AllOpps-Products'[Prob.]) = 80 && max(allopps-products[status])="open", "30 Days",
    DATEDIFF(MAX('AllOpps-Products'[Est.Ship]),TODAY(),DAY)> 90, "Older than 90",
    DATEDIFF(MAX('AllOpps-Products'[Est.Ship]),TODAY(),DAY)> 60, "Older than 60",
    DATEDIFF(MAX('AllOpps-Products'[Est.Ship]),TODAY(),DAY)> 30, "Older than 30",
    DATEDIFF(MAX('AllOpps-Products'[Est.Ship]),TODAY(),DAY)> 15, "30 Days",
    FALSE
)

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

@amitchandak  (or anyone that can answer)

 

The solution from Amit is great, with one exception.   

 

How to deal with a date that is in the past?    Example: 

 

The estimated close date may indeed be 15 days or more from today's date....but it could be 15 days in the past from today  (not 15 days FROM today).    For those estimated close dates that have passed already (from today's current date), how to address in the Switch statement?

az38
Community Champion
Community Champion

Hi @Anonymous 

smth like

DATEDIFF(MAX('AllOpps-Products'[Est.Ship]),TODAY(),DAY)> 0, "0 Days",
DATEDIFF(MAX('AllOpps-Products'[Est.Ship]),TODAY(),DAY)> -15, "Passed already",

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

Thanks AZ.  @az38     But I am getting some strange results.   May 29 is two days away, but it is shows "pass already" as a result.     The table on the left using the formula.   The table on the right is a list of opportunities and their estimated close/ship date.   

 

passedalready.png

az38
Community Champion
Community Champion

@Anonymous 

it will work only if you previously add row with 0 value comparision as in my example

DATEDIFF(MAX('AllOpps-Products'[Est.Ship]),TODAY(),DAY)> 0, "0 Days",

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

@az38  I got it to work using this: 

 

TRUE(),
    DATEDIFF(MAX('AllOpps-Products'[Est.Ship]),TODAY(),DAY) > -1 &&  DATEDIFF(MAX('AllOpps-Products'[Est.Ship]),TODAY(),DAY) > -20, "Passed already"
Anonymous
Not applicable

@az38  Hi AZ  -   Yes, if you are talking about including it in the measure you created, it is there, but that is the result I am getting. 

 

Here is another example.   This time in June.   It is showing that this opportunity's estimate ship date has "passed already" but it still about 20 days into the future.  

 

pass already.png

 

 

harshnathani
Community Champion
Community Champion

@Anonymous 
 
You can add  allopps-products[status]="open" using  && notation
 
 
SWITCH(
    TRUE(),
    MAX('AllOpps-Products'[Prob.])  = 80 && allopps-products[status]="open" , "30 Days",
    DATEDIFF(MAX('AllOpps-Products'[Est.Ship]),TODAY(),DAY)> 90, "Older than 90",
    DATEDIFF(MAX('AllOpps-Products'[Est.Ship]),TODAY(),DAY)> 60, "Older than 60",
    DATEDIFF(MAX('AllOpps-Products'[Est.Ship]),TODAY(),DAY)> 30, "Older than 30",
    DATEDIFF(MAX('AllOpps-Products'[Est.Ship]),TODAY(),DAY)> 15, "30 Days",
    
)
 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

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.