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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
mrolly
Regular Visitor

Help: Insert Shift into Data Table Based On Time Parameters

Hello Internet Friends,

 

I'm having trouble figuring out how to insert a column into a datatable that I'm querying in, to show what particular shift a Transaction Time fell within. I'll then be using this Shift information to create Data Slicer filters for 1st and 2nd Shift for analytical purposes.

 

At where I currently work, there are 2 shifts. There are:

1st Shift = 7:00 AM (Current Day) to 3:30 PM (Current Day)

2nd Shift = 3:30 PM (Current Day) to 1:00 AM (Next Day)

 

Ideally, if the Transaction Time falls within the time range between 7 AM to 3:30 PM, then it would show 1st Shift and the same the Transaction Time fell within the time range of 3:30 PM to 1:00 AM (Next Day), then it would show 2nd Shift.

 

Any help would be much appreciated! I also have a Simple Data Table (shown below) that I created, perhaps there's a better solution to add Shift Parameters in there in a column, not sure. Open to whatever! Thank you!

 

 

ShiftTableExample.PNG

DateTable.PNG

1 ACCEPTED SOLUTION
FreemanZ
Community Champion
Community Champion

hi @mrolly ,

 

try to write a calculated column like:

Column = 

VAR _time = [Transaction Time] -TRUNC([Transaction Time])

RETURN

SWITCH(

    TRUE(),

    _time >= 7/24&&_time<15.5/24,

    "Shift1",

    _time >=15.5/24&&_time<1/24,

    "Shift2"

)

View solution in original post

3 REPLIES 3
mrolly
Regular Visitor

@FreemanZ , I played around with it a little bit and figured it out! Just adding the solution that worked for me here for anybody in the future that is trying to do this so they have the working calc!

mrolly_0-1730923187610.png

 

FreemanZ
Community Champion
Community Champion

hi @mrolly ,

 

try to write a calculated column like:

Column = 

VAR _time = [Transaction Time] -TRUNC([Transaction Time])

RETURN

SWITCH(

    TRUE(),

    _time >= 7/24&&_time<15.5/24,

    "Shift1",

    _time >=15.5/24&&_time<1/24,

    "Shift2"

)

Hey @FreemanZ ! Thank you so much for taking an attempt at this. I inserted your formula into the Table and it returned the 1st Shift properly, but failed on the 2nd Shift. I think it may have to do with the AM/PM of the Transaction Times, but I'm not certain. Have a look down below.

 

Maybe it's adding a statement that if Blank, show the text "2nd Shift"? 

 

TableExample2.PNG

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

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.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.