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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
jmetf150
Helper I
Helper I

Switch with dates and text values/format

I am trying to write a SWITCH function that looks at a TEXT column ( [RS] ), and depending on the text value "OT", then compares between two other DATE columns ( [RDD] & [RCD] )to derive another TEXT column. 

 

Cond = 
switch(
   'R'[RS]="OT",
   'R'[RDD]<='R'[RCD], "PD",
   "LLT"
)

 

 

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@jmetf150 I think you want: 

Cond = 
switch(TRUE(),
   'R'[RS]="OT", IF('R'[RDD]<='R'[RCD], "PD", "LLT")
)


or

Cond = 
switch('R'[RS],
   "OT", IF('R'[RDD]<='R'[RCD], "PD", "LLT")
)


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

8 REPLIES 8
jmetf150
Helper I
Helper I

@Greg_Deckler to piggy back on this topic on IF/SWITCH, how would I do write the below formula if if I wanted to see orders that are "Late" (i.e. arriving after our need date) and if they are late, are they late in the past (i.e. PO del was last month)  or are they late in the future (ie Need date is next month but current PO Due date is even after that). 

 

The below is what I have know

LateStatus = if(ZMMAE[OT X 2 to Cur MRP Need]="Late" && if(ZMMAE[Del Date]>ZMMAE[Cur MRP Need], "Late in Past" && if(ZMMAE[Del Date]<ZMMAE[Cur MRP Need],"Late in the Future",""))

and I keep getting "Too few arguments were passed to the IF cunction.minimum argument is 2....".

@jmetf150 Try:

 

 

LateStatus = 
  SWITCH( TRUE(),
    ZMMAE[OT X 2 to Cur MRP Need]="Late" && ZMMAE[Del Date]>ZMMAE[Cur MRP Need], "Late in Past",
    ZMMAE[OT X 2 to Cur MRP Need]="Late" && ZMMAE[Del Date]<ZMMAE[Cur MRP Need],"Late in the Future",
    ""
  )

 

 



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...

That is working to only pull the "Late" orders but it is saying all of the late orders are "In THe Past".  I am fairly certain that is incorrect but the source data consists of over 7K lines so let me find one that is "Late in the Future" and see what it is pulling that way.

jmetf150
Helper I
Helper I

@Greg_Deckler can you explain the difference between both of your solutions and when you would use one over the other?

@jmetf150 Well, you would use a "normal" SWITCH statement when you have different values you want to return for different values in a column for example. There's no complex logic required in terms of when you want to return which values. So, let's say you have a column that can contain Pickle, Banana or Cucumber and you want to return 1 for Pickle, 2 for Banana and 3 for Cucumber. This is the second example.

 

The 1st example, the SWITCH(TRUE() ) statement is used when you have complex criteria, so return 1 if Pickle and the Value is > 30 for example.

 

Also note that in this specific use case, you could have used an IF statement, 

IF( 'R'[RS]="OT" && 'R'[RDD]<='R'[RCD], "PD", "LLT")


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...
Greg_Deckler
Community Champion
Community Champion

@jmetf150 I think you want: 

Cond = 
switch(TRUE(),
   'R'[RS]="OT", IF('R'[RDD]<='R'[RCD], "PD", "LLT")
)


or

Cond = 
switch('R'[RS],
   "OT", IF('R'[RDD]<='R'[RCD], "PD", "LLT")
)


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...

Deleted so not to confuse anyone

Ok....I figured it out...my inital formula was incorrect...I was using an "="OT"" sign when I should have been using a "<>""OT".....Thank you very much for the soltuion Greg!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.