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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
HannaK
Frequent Visitor

Check if times are in certain range

Hello, I was looking for a problem like mine but didn't really find anything like that.

 

I have dates in a format m/d/yyyy h:nn:ss AM/PM.

 

For every record I have:

- creation date and time

- closing date and time

 

For example:

created 2/13/2023 2:32:23 PM

closed 2/15/2023 3:21:23 PM

 

What I have to prepare, is to check whether the creation and closing were made in the same time range or not. Time ranges are 9AM to 5PM, 5PM to 1AM and 1AM to 9AM. So if something was created for example at 10AM and closed at 2PM (no matter the day), it's "OK", if created at 3PM but closed at 8PM it will be "FAIL".

 

I tried some "IF" and "AND" formulas but nothing seemed to work. I am a beginner so maybe I don't see something obvious... Would be grateful for your help.

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@HannaK Maybe:

Column =
  VAR __StartHour = HOUR([creation date and time])
  VAR __EndHour = HOUR([closing date and time])
  VAR __Result = 
    SWITCH( TRUE(),
      __StartHour >= 9 && __StartHour <= 16 && __EndHour >= 9 && __EndHour <= 16, "OK",
      ( __StartHour >= 17 || __StartHour = 0 ) && ( __EndHour >= 17 || __EndHour <= 0), "OK",
      __StartHour >= 1 && __StartHour <= 8 && __EndHour >= 1 && __EndHour <= 8, "OK",
      "FAIL"
    )
RETURN
  __Result

 


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

2 REPLIES 2
Greg_Deckler
Community Champion
Community Champion

@HannaK Maybe:

Column =
  VAR __StartHour = HOUR([creation date and time])
  VAR __EndHour = HOUR([closing date and time])
  VAR __Result = 
    SWITCH( TRUE(),
      __StartHour >= 9 && __StartHour <= 16 && __EndHour >= 9 && __EndHour <= 16, "OK",
      ( __StartHour >= 17 || __StartHour = 0 ) && ( __EndHour >= 17 || __EndHour <= 0), "OK",
      __StartHour >= 1 && __StartHour <= 8 && __EndHour >= 1 && __EndHour <= 8, "OK",
      "FAIL"
    )
RETURN
  __Result

 


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

Thank you! Looks that it's working properly.

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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