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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join 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
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

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.