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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Best Power Query Table for Transformation - Creating Schedule Activities to Match Actual Activities

Good day, I recently created a PowerApp that captures the Activity Start and End of Employees based on their tagging. The result is this table.

EmployeeActivityDateActivity StartActivity End

AProductive12/15/202312:22:58 PM12:48:31 PM
AProductive12/15/202312:48:31 PM12:54:17 PM
AProductive12/15/202312:54:17 PM12:54:20 PM
AProductive12/15/202312:54:20 PM1:00:17 PM
ALunch12/15/20231:00:17 PM1:52:13 PM
AProductive12/15/20231:52:13 PM1:52:14 PM
AProductive12/15/20231:52:14 PM2:50:37 PM
AProductive12/15/20232:50:37 PM3:18:59 PM
AProductive12/15/20234:03:58 PM4:04:05 PM
AProductive12/15/20234:04:05 PM4:04:13 PM
AProductive12/15/20234:04:13 PM4:04:18 PM
ABreak12/15/20234:04:18 PM4:10:03 PM
AProductive12/15/20234:10:03 PM4:10:04 PM
AProductive12/15/20234:10:04 PM4:31:04 PM


I'm planning to create another app that creates a schedule for those agents, so I can generate a report fo their adherence% and to get the variance of minutes if planned/scheduled activity doesn't reflect to their actualy statuses.

In order to do so, what's the best table to create in Lists order to match the actual activity when exported to Power Query. 
 Table 1:
EmployeeShiftShift DateShift StartShift EndOpen Time StartOpen Time EndBreak 1 StartBreak 1 EndLunch StartLunch EndBreak 2 StartBreak 2 End

AProductive12/16/20239:00 AM6:00 PM9:00 AM6:00 PM11:00 AM11:15 AM1:00 PM2:00 PM3:00 PM3:15 PM


Concern for Table 1: I am unsure on how I would add the Open Time activity between the intervals of non productive statuses. I'm thinking of creating additional Columns like Open Time 1, Open Time 2.

Table 2:
EmployeeActivityShift DateActivity StartActivity End

AOpen Time12/16/20239:00 AM11:00 PM
ABreak 112/16/202311:00 AM11:15 PM
AOpen Time12/16/202311:15 PM1:00 PM
ALunch12/16/20231:00 PM2:00 PM
AOpen Time12/16/20232:00 PM3:00 PM
ABreak 212/16/20233:00 PM3:15 PM
AOpen Time12/16/20233:15 PM6:00 PM


Concern for Table 2: 
- I won't be able to add the Shift Start and Shift End which I wanted to have in order to get the Login and Logout time of each employee.
- It would create multiple items which would fill up the list quickly.

Any ideas or suggestions are highly appreciated. Thank you.





1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous 

For the table2, you can put the following code to advanced editor in power query

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUfIvSM1TCMnMTQWyDY30Dc30jQyMjIEcSysDAwVHX5CwIYgZ4KsUqwPR41SUmpitYIiuA6IOpsXQFFkLTmvgKoFMNGt8SvOSMzDUQxXpKBmhKcdphRFcizFWjxihazBG0kCkN4zhvjCD2RELAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Employee = _t, Activity = _t, #"Shift Date" = _t, #"Activity Start" = _t, #"Activity End" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Employee", type text}, {"Activity", type text}, {"Shift Date", type date}, {"Activity Start", type time}, {"Activity End", type time}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each [Shift Date]&[Activity Start]),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each [Shift Date]&[Activity End]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom1",{{"Custom", type datetime}, {"Custom.1", type datetime}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type1", "Index", 1, 1, Int64.Type),
    #"Added Custom2" = Table.AddColumn(#"Added Index", "ShiftStart", each List.Min(Table.SelectRows(#"Added Index",(x)=>x[Employee]=[Employee] and x[Index]=List.Min(#"Added Index"[Index]))[Custom])),
    #"Added Custom3" = Table.AddColumn(#"Added Custom2", "ShiftEnd", each List.Min(Table.SelectRows(#"Added Index",(x)=>x[Employee]=[Employee] and x[Index]=List.Max(#"Added Index"[Index]))[Custom.1])),
    #"Changed Type2" = Table.TransformColumnTypes(#"Added Custom3",{{"ShiftStart", type datetime}, {"ShiftEnd", type datetime}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type2",{"Custom", "Custom.1", "Index"})
in
    #"Removed Columns"

Outpout

vxinruzhumsft_0-1702867067099.png

Best Regards!

Yolo Zhu

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

1 REPLY 1
Anonymous
Not applicable

Hi @Anonymous 

For the table2, you can put the following code to advanced editor in power query

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUfIvSM1TCMnMTQWyDY30Dc30jQyMjIEcSysDAwVHX5CwIYgZ4KsUqwPR41SUmpitYIiuA6IOpsXQFFkLTmvgKoFMNGt8SvOSMzDUQxXpKBmhKcdphRFcizFWjxihazBG0kCkN4zhvjCD2RELAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Employee = _t, Activity = _t, #"Shift Date" = _t, #"Activity Start" = _t, #"Activity End" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Employee", type text}, {"Activity", type text}, {"Shift Date", type date}, {"Activity Start", type time}, {"Activity End", type time}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each [Shift Date]&[Activity Start]),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each [Shift Date]&[Activity End]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom1",{{"Custom", type datetime}, {"Custom.1", type datetime}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type1", "Index", 1, 1, Int64.Type),
    #"Added Custom2" = Table.AddColumn(#"Added Index", "ShiftStart", each List.Min(Table.SelectRows(#"Added Index",(x)=>x[Employee]=[Employee] and x[Index]=List.Min(#"Added Index"[Index]))[Custom])),
    #"Added Custom3" = Table.AddColumn(#"Added Custom2", "ShiftEnd", each List.Min(Table.SelectRows(#"Added Index",(x)=>x[Employee]=[Employee] and x[Index]=List.Max(#"Added Index"[Index]))[Custom.1])),
    #"Changed Type2" = Table.TransformColumnTypes(#"Added Custom3",{{"ShiftStart", type datetime}, {"ShiftEnd", type datetime}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type2",{"Custom", "Custom.1", "Index"})
in
    #"Removed Columns"

Outpout

vxinruzhumsft_0-1702867067099.png

Best Regards!

Yolo Zhu

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

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Top Solution Authors