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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
PWSNEALE
Frequent Visitor

Return a value based on time range

Hello, 

 

I have a table that has a column named SubEventTime and some other irrelevent columns to my question. I need to add a column that will show what shif the event occoured on based on the SubEventTime. I have tried using IF and SWITCH statements, but still cannot get anything to work. 

 

Time Ranges

6:00 am - 2:30 pm  Return 1st shift

2:30 pm - 12:30 am return 2nd Shift

12:30 am - 6:00 am return 3rd shift

 

Thanks in advance

 

Steve

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @PWSNEALE ,

Please try this way:

SHIFT = 
VAR CurrentTime = 'Table'[time]
VAR StartTime_1st = TIME(6, 0, 0)
VAR EndTime_1st = TIME(14, 30, 0)
VAR StartTime_2nd = EndTime_1st
VAR EndTime_2nd = TIME(24, 30, 0)
RETURN
    IF(
        AND(CurrentTime >= StartTime_1st, CurrentTime < EndTime_1st),
        "1st shift",
        IF(
            OR(
                AND(CurrentTime >= StartTime_2nd, CurrentTime < EndTime_2nd),
                AND(CurrentTime >= TIME(0, 0, 0), CurrentTime < StartTime_1st)
            ),
            "2nd shift",
            "3rd shift"
        )
    )

vjunyantmsft_0-1702432500426.png


Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @PWSNEALE ,

Please try this way:

SHIFT = 
VAR CurrentTime = 'Table'[time]
VAR StartTime_1st = TIME(6, 0, 0)
VAR EndTime_1st = TIME(14, 30, 0)
VAR StartTime_2nd = EndTime_1st
VAR EndTime_2nd = TIME(24, 30, 0)
RETURN
    IF(
        AND(CurrentTime >= StartTime_1st, CurrentTime < EndTime_1st),
        "1st shift",
        IF(
            OR(
                AND(CurrentTime >= StartTime_2nd, CurrentTime < EndTime_2nd),
                AND(CurrentTime >= TIME(0, 0, 0), CurrentTime < StartTime_1st)
            ),
            "2nd shift",
            "3rd shift"
        )
    )

vjunyantmsft_0-1702432500426.png


Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you! this worked well.

ExcelMonke
Super User
Super User

Have you considered using:

Shift = 
SWITCH(
TRUE(),
IF(AND(TIMEVALUE("06:00:00")>TIMEVALUE(Table[Time]) , TIMEVALUE("14:30:00")<Table[Time])),"1st Shift",
IF(AND(TIMEVALUE("14:30:00")>TIMEVALUE(Table[Time]) , TIMEVALUE("00:30:00")<Table[Time])),"2nd Shift",
IF(AND(TIMEVALUE("00:30:00")>TIMEVALUE(Table[Time]) , TIMEVALUE("06:00:00")<Table[Time])),"3rd Shift",
0
)

Do note, you may need to adjust for >= and <= depending on your parameters.

Hope this helps!





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

Proud to be a Super User!





ToddChitt
Super User
Super User

Can you post some real data, or at least a screen shot? Also please show your attempts with the DAX IF statement. This should not be too hard:

IF ( [SubEventTime] = "6:00 am - 2:30 pm", "1st shift",

     IF ( ...

         IF ( ....)

        )

    )




Did I answer your question? If so, mark my post as a solution. Also consider helping someone else in the forums!

Proud to be a Super User!





Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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