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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.