I have an Excel table with columns for date, office, and timestamps manually inserted:
- Workblocks always occur within a single day, and the first timestamp of the day marks the start of a workblock.
- First timestamp of the day is always a startpoint of a workblock
- There might be errors in the data, but I want to focus on calculating workblock durations first -> if a day is not complete (no even number of timestamps) just leave this one out for now
- The office column shows if i worked in the office or from home (1 = in the office)
I've loaded the data into Power BI, performed indexing, and created a combined time/date column.
I'd like to create a new table in Power BI that shows a row for each workblock with the following columns:
- date [dd.mm.yyy]
- office [0,1]
- duration [hh:mm]
Illustration of what the table could look like in power bi:
From the herewith ilustrated blocks:
If easier the durations can be in hh:mm or in hh.min format at the end i need both and think im able to convert vice versa.
Thank you so much <3
What i already tried is using lag and i was thinking of generating a new column with the previous timestamp in it whenever its on same day. this would work but also would give me blocks for the breaks. which is also nice but then it should mark them as work or break so i can then use them to illustrate. But how do i know when a block is work or if it is break time?




Given a starting table of:
Try the following:
Explaination:
Rows1)Rows2) which takes the odd rows of timestamp andZipwith the even rows. Then transform with subtracting the two. Then create table of the previous transformed list with the odd rows of theofficecolumn, and then add the index.Rows1and expandRows2.Result