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

View all the Fabric Data Days sessions on demand. View schedule

Reply
AlexanderPrime
Solution Supplier
Solution Supplier

Date / Time Table Crossjoin issues (Shift Identification)

Hi there.

 

I'm having issues making a lookup to pull shift identifications against a Date/Time table in the 24 hour format (All UTC as this is pulling from D365)

 

I have a table with a Shift Time List like the below: (Calling it ShiftTimes table for this query)

 

Date Group Shift Start End
31/01/2022 A Night 00:00 06:30
31/01/2022 A Day 06:30 18:30
31/01/2022 A Night 18:30 00:00
01/02/2022 A Night 00:00 06:30
01/02/2022 A Day 06:30 18:30
01/02/2022 A Night 18:30 00:00

 

And I'm trying to get it so if a row in another table is reporting that a task is completed by Group A at a certain time, then it can flag if it's the Day or Night shift, however the shift times will vary (and is stored on D365) so the table records this by individual date like the above ShiftTimes table based on group.

 

Example of expected result

Date Time Group Shift
31/01/2022 09:27 A Day

 

I tried using Crossjoin with a Date/Time table. but to do one for each minute over a space of a year would have at least 525k multipled by the crossjoin result, and as such the Crossjoin table won't finish loading due to volume, am I overlooking something simple? 


Please note - I am not affiliated with Microsoft, I'm just an end user like yourself.
Just a regular guy doin' Data Science.

If my post has helped you, please don't forget to thumbs up or click "Accept as solution" if it solved your problem!
1 ACCEPTED SOLUTION
Mikelytics
Resident Rockstar
Resident Rockstar

Hi @AlexanderPrime 

 

I might have an approach with calculated columns. Typically I try to avoid calculated columns but here it might be a valid solution:

 

my base data:

ShiftTimes: I added in the table a shift ID using the Index column featuire from Power Query.

Mikelytics_10-1669664060955.png

 

 

On top I added a Start and EndTime combining Date and Time. Here I did it as a calculated column. You can also do it in Power Query upfront.

 

Result of ShiftTimes Table

Mikelytics_4-1669663509065.png

 

Activity Table: also with added combination of date and time

Mikelytics_5-1669663636281.png

Based on the ActivityDateTime I identify in a calculated column the related shift ID with the following formula. Please be aware that there should not be an overlap of DateTime between different shifts. Otherwise you will need to use MAX or MIN instead of SELECTEDVALUE

Mikelytics_0-1669664452912.png

 

 

RelatedShiftID = 

CALCULATE(
   SELECTEDVALUE(ShiftTimes[ShiftID]),
   FILTER(
      ShiftTimes,
      ShiftTimes[DateTimeStart] <= [ActivityDateTime] && 
      ShiftTimes[DateTimeEnd] >= [ActivityDateTime]
   )
)

 

now you have the ShiftID in your actvity table and you can based on the ID add the other information from the ShiftTimes table, like the Group

Mikelytics_9-1669663992909.png

 

 

Group = 

var var_CurrentShiftID = [RelatedShiftID]

RETURN

CALCULATE(
   SELECTEDVALUE(ShiftTimes[Group]),
   ShiftTimes[ShiftID] = var_CurrentShiftID
)

 

and the Shift

Mikelytics_8-1669663954985.png

 

Shift = 

var var_CurrentShiftID = [RelatedShiftID]

RETURN

CALCULATE(
   SELECTEDVALUE(ShiftTimes[Shift]),
   ShiftTimes[ShiftID] = var_CurrentShiftID
)

 

 

Best regards

Michael

-----------------------------------------------------

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your thumbs up!

@ me in replies or I'll lose your thread.

-----------------------------------------------------

LinkedIn

 

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

View solution in original post

4 REPLIES 4
Mikelytics
Resident Rockstar
Resident Rockstar

Hi @AlexanderPrime 

 

I might have an approach with calculated columns. Typically I try to avoid calculated columns but here it might be a valid solution:

 

my base data:

ShiftTimes: I added in the table a shift ID using the Index column featuire from Power Query.

Mikelytics_10-1669664060955.png

 

 

On top I added a Start and EndTime combining Date and Time. Here I did it as a calculated column. You can also do it in Power Query upfront.

 

Result of ShiftTimes Table

Mikelytics_4-1669663509065.png

 

Activity Table: also with added combination of date and time

Mikelytics_5-1669663636281.png

Based on the ActivityDateTime I identify in a calculated column the related shift ID with the following formula. Please be aware that there should not be an overlap of DateTime between different shifts. Otherwise you will need to use MAX or MIN instead of SELECTEDVALUE

Mikelytics_0-1669664452912.png

 

 

RelatedShiftID = 

CALCULATE(
   SELECTEDVALUE(ShiftTimes[ShiftID]),
   FILTER(
      ShiftTimes,
      ShiftTimes[DateTimeStart] <= [ActivityDateTime] && 
      ShiftTimes[DateTimeEnd] >= [ActivityDateTime]
   )
)

 

now you have the ShiftID in your actvity table and you can based on the ID add the other information from the ShiftTimes table, like the Group

Mikelytics_9-1669663992909.png

 

 

Group = 

var var_CurrentShiftID = [RelatedShiftID]

RETURN

CALCULATE(
   SELECTEDVALUE(ShiftTimes[Group]),
   ShiftTimes[ShiftID] = var_CurrentShiftID
)

 

and the Shift

Mikelytics_8-1669663954985.png

 

Shift = 

var var_CurrentShiftID = [RelatedShiftID]

RETURN

CALCULATE(
   SELECTEDVALUE(ShiftTimes[Shift]),
   ShiftTimes[ShiftID] = var_CurrentShiftID
)

 

 

Best regards

Michael

-----------------------------------------------------

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your thumbs up!

@ me in replies or I'll lose your thread.

-----------------------------------------------------

LinkedIn

 

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

Perfect. That did the trick, many thanks!


Please note - I am not affiliated with Microsoft, I'm just an end user like yourself.
Just a regular guy doin' Data Science.

If my post has helped you, please don't forget to thumbs up or click "Accept as solution" if it solved your problem!
djurecicK2
Super User
Super User

Hi @AlexanderPrime ,

 Here is a possible idea- is everything between 00:00 and 06:30 and 18:30 to 00:00 always night shift? (and 06:30 to 18:30 always day shift?)

 

If you have the time of task completion, could you just write a statement that assigns shift based on these values?

If taskcompletiontime >= 06:30 && <=18:30, then day shift, else night shift 

The shift times are subject to change so unfortunately this approach wouldn't work, I wish it was that straightforward though! Thanks. 


Please note - I am not affiliated with Microsoft, I'm just an end user like yourself.
Just a regular guy doin' Data Science.

If my post has helped you, please don't forget to thumbs up or click "Accept as solution" if it solved your problem!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors