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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
jusTodd
Advocate IV
Advocate IV

Compare two rows and adjust Date/Time for one based on another

I need to bring two rows of timesheet data together to display the correct dates and times, when and if it happens.

 

Attempting to display schedules and timesheets (two independent datasets) in a calendar view (Calendar Visual by MAC Software).

 

Schedules and Timesheets often cross the midngiht hour (24/7/365 operation).

 

I resolved that issue with a couple calculations, creating new START and END date/times.  The schedules now display nicely for those crossing the midnight hour.

 

However, the effort seems to created a problem that I am not quite sure how (or if) I can overcome.

 

Sometimes an individual working Regular time slips into Overtime, resulting in two rows in Timesheets.  

 

Here is a sample of one individual.   [Timesheet Starts] and [Timesheet Ends] are my calculated columns.

 

 

Shift DateShift StartShift FinishTeamActual HoursDet CodeTimesheet StartsTimesheetHrs2SecondsTimesheetDurationTimesheet Ends
21-Sep-2312:00 PM7:00 PMDC1.60OTWK19/21/2023 12:0057600.0666666679/21/2023 1:36:00 PM
21-Sep-2312:00 PM7:00 PMDC5.40REGWK19/21/2023 12:00194400.2259/21/2023 5:24:00 PM

 

 

As you can tell, they both end up with the same [Timesheet Starts] time.

 

I need OT start time to pick up where regular time leaves off, when and if it does happen.

 

Any advice on how I might resovle this is welcome.  Ideally, I would end up with something like this:

Shift DateShift StartShift FinishTeamActual HoursDet CodeTimesheet StartsTimesheetHrs2SecondsTimesheetDurationTimesheet Ends
21-Sep-2312:00 PM7:00 PMDC1.60OTWK19/21/2023 17:2457600.0666666679/21/2023 7:00:00 PM
21-Sep-2312:00 PM7:00 PMDC5.40REGWK19/21/2023 12:00194400.2259/21/2023 5:24:00 PM

 

 

 

1 ACCEPTED SOLUTION

Thanks for the response @lbendlin .  The unique ID is in another table, which ultimately joins with EEID in this table.

 

I did figure out a sort of solution over the week.

 

  1. Get Timesheet Start
  2. Get Timesheet End
  3. Calculate new stuff ...
    1. REG Timesheet End = IF REGWK1, add duration hours to Timesheet Start
    2. OT Timesheet Start = IF OTWK1, subtract hours from Timesheet End
  4. Populate new columns for Actual Timesheet Start/End using a conditional on the originals and the recalculated.
    1. Accounts for any situations where the whole of the shift is OT as well.
  5. Now ... I have actual start and actual end date/times for the timesheets that have more than one row, due to OT.

View solution in original post

2 REPLIES 2
lbendlin
Super User
Super User

Can you have overtime that bleeds into the next shift / day ?

What is your unique identifier?  Shift Date + Shift Start + Team?

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjLUDU4t0DUyVtJRMjSyMjBQCPAFMs3hLBdnkIyemQGQ8g8J9zYE0pb6Rob6RgZGxgpgLUARU3OwAgM9AzMIMEdVZmVsBjUxVodYS031TEBmBrm647LV0NLEBGKtkZEpkFaKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Shift Date" = _t, #"Shift Start" = _t, #"Shift Finish" = _t, Team = _t, #"Actual Hours" = _t, #"Det Code" = _t, #"Timesheet Starts" = _t, TimesheetHrs2Seconds = _t, TimesheetDuration = _t, #"Timesheet Ends" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Shift Date", type date}, {"Shift Start", type time}, {"Shift Finish", type time}, {"Team", type text}, {"Actual Hours", type number}, {"Det Code", type text}, {"Timesheet Starts", type datetime}, {"TimesheetHrs2Seconds", Int64.Type}, {"TimesheetDuration", type number}, {"Timesheet Ends", type datetime}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type",each [Timesheet Ends],each if [Det Code]="REGWK1" then [Timesheet Starts] + #duration(0,0,[Actual Hours]*60,0) else [Timesheet Starts] + #duration(0,0,List.Sum(#"Changed Type"[Actual Hours])*60,0),Replacer.ReplaceValue,{"Timesheet Ends"})
in
    #"Replaced Value"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

Thanks for the response @lbendlin .  The unique ID is in another table, which ultimately joins with EEID in this table.

 

I did figure out a sort of solution over the week.

 

  1. Get Timesheet Start
  2. Get Timesheet End
  3. Calculate new stuff ...
    1. REG Timesheet End = IF REGWK1, add duration hours to Timesheet Start
    2. OT Timesheet Start = IF OTWK1, subtract hours from Timesheet End
  4. Populate new columns for Actual Timesheet Start/End using a conditional on the originals and the recalculated.
    1. Accounts for any situations where the whole of the shift is OT as well.
  5. Now ... I have actual start and actual end date/times for the timesheets that have more than one row, due to OT.

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

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.