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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
nataliesmiy1357
Helper IV
Helper IV

DAX Formula - Time

Hello!  I am looking to create a formula that's if this and that, then this with time.

 

I want:  If the time is between 6am-5:10pm, then "First Shift"

          and  if the time is between 5:25pm - 5:55am, then "Second Shift"

 

Thanks in advance! 

1 ACCEPTED SOLUTION
rajendraongole1
Super User
Super User

Hi @nataliesmiy1357 - create below calculated column in your table, replace your Datetime column as per your model.

 

Shift Classification =
VAR CurrentTime = [DateTime]  
VAR TimeFirstShiftStart = TIME(6, 0, 0)   -- 6:00 AM
VAR TimeFirstShiftEnd = TIME(17, 10, 0)   -- 5:10 PM
VAR TimeSecondShiftStart = TIME(17, 25, 0)  -- 5:25 PM
VAR TimeSecondShiftEnd = TIME(5, 55, 0)  -- 5:55 AM (next day)

RETURN
IF (
    (CurrentTime >= TimeFirstShiftStart && CurrentTime <= TimeFirstShiftEnd) ||
    (CurrentTime >= TimeSecondShiftStart || CurrentTime <= TimeSecondShiftEnd),
    "First Shift",
    "Second Shift"
)

 

rajendraongole1_1-1723570791647.png

 

Hope it helps

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

1 REPLY 1
rajendraongole1
Super User
Super User

Hi @nataliesmiy1357 - create below calculated column in your table, replace your Datetime column as per your model.

 

Shift Classification =
VAR CurrentTime = [DateTime]  
VAR TimeFirstShiftStart = TIME(6, 0, 0)   -- 6:00 AM
VAR TimeFirstShiftEnd = TIME(17, 10, 0)   -- 5:10 PM
VAR TimeSecondShiftStart = TIME(17, 25, 0)  -- 5:25 PM
VAR TimeSecondShiftEnd = TIME(5, 55, 0)  -- 5:55 AM (next day)

RETURN
IF (
    (CurrentTime >= TimeFirstShiftStart && CurrentTime <= TimeFirstShiftEnd) ||
    (CurrentTime >= TimeSecondShiftStart || CurrentTime <= TimeSecondShiftEnd),
    "First Shift",
    "Second Shift"
)

 

rajendraongole1_1-1723570791647.png

 

Hope it helps

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.