Forum Discussion
Recreating excel operations
- 1 year ago
Hi MRM_CCM , is this what you are looking for? I'll just attach the images of the output and code the used. Thanks!
Here's the code:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Lastname", type text}, {"Firstname", type text}, {"InPunchDate", type datetime}, {"InPunchTime", type time}, {"OutPunchDate", type datetime}, {"OutPunchTime", type time}, {"EarnHours", type number}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Lastname", "Firstname", "InPunchDate", "OutPunchDate"}, {{"All", each _},{"Sum", each List.Sum(_[EarnHours])}})[[All],[Sum]],
Try1 = Table.AddColumn(#"Grouped Rows","RowCount", each Table.RowCount(_[All]) - 1),
Try2 = Table.AddColumn(Try1,"List", each {1.._[RowCount]}),
Try3 = Table.TransformColumns(Try2,{"List", each List.Transform(_, each 0)}),
#"Expanded List" = Table.ExpandListColumn(Try3, "List"),
SumNos = List.RemoveNulls(List.Combine(List.Zip({#"Expanded List"[Sum],#"Expanded List"[List]}))),
#"Expanded All" = Table.ExpandTableColumn(#"Expanded List"[[All]], "All", {"Lastname", "Firstname", "InPunchDate", "InPunchTime", "OutPunchDate", "OutPunchTime", "EarnHours"}, {"Lastname", "Firstname", "InPunchDate", "InPunchTime", "OutPunchDate", "OutPunchTime", "EarnHours"}),
FinTable = Table.TransformColumns(Table.AddIndexColumn(#"Expanded All","H3",0,1), {"H3", each SumNos{_}})
in
FinTable
| Lastname | Firstname | InPunchDate | InPunchTime | OutPunchDate | OutPunchTime | EarnHours | h1 | h2 | h3 |
| Jones | Indiana | 1/2/2025 | 6:27 AM | 1/2/2025 | 10:57 AM | 4.5 | 8.08 | 8.08 | |
| Jones | Indiana | 1/2/2025 | 11:56 AM | 1/2/2025 | 3:31 PM | 3.58 | 0 | 0 | 0 |
| Jones | Indiana | 1/3/2025 | 6:28 AM | 1/3/2025 | 10:55 AM | 4.45 | 8.05 | 0 | 8.05 |
| Jones | Indiana | 1/3/2025 | 11:54 AM | 1/3/2025 | 3:30 PM | 3.6 | 0 | 0 | 0 |
| Jones | Indiana | 1/4/2025 | 6:58 AM | 1/4/2025 | 12:00 PM | 5.03 | 0 | 5.03 | 5.03 |
| Jones | Indiana | 1/6/2025 | 6:28 AM | 1/6/2025 | 10:55 AM | 4.45 | 8.05 | 0 | 8.05 |
| Jones | Indiana | 1/6/2025 | 11:54 AM | 1/6/2025 | 3:30 PM | 3.6 | 0 | 0 | 0 |
| Jones | Indiana | 1/7/2025 | 6:28 AM | 1/7/2025 | 10:54 AM | 4.43 | 8.05 | 0 | 8.05 |
| Jones | Indiana | 1/7/2025 | 11:53 AM | 1/7/2025 | 3:30 PM | 3.62 | 0 | 0 | 0 |
| Conner | Sarah | 1/2/2025 | 7:28 AM | 1/2/2025 | 12:13 PM | 4.75 | 8.57 | 0 | 8.57 |
| Conner | Sarah | 1/2/2025 | 1:11 PM | 1/2/2025 | 5:00 PM | 3.82 | 0 | 0 | 0 |
| Conner | Sarah | 1/3/2025 | 7:29 AM | 1/3/2025 | 12:11 PM | 4.7 | 8.52 | 0 | 8.52 |
| Conner | Sarah | 1/3/2025 | 1:11 PM | 1/3/2025 | 5:00 PM | 3.82 | 0 | 0 | 0 |
| Conner | Sarah | 1/6/2025 | 7:30 AM | 1/6/2025 | 12:54 PM | 5.4 | 8.52 | 0 | 8.52 |
| Conner | Sarah | 1/6/2025 | 1:54 PM | 1/6/2025 | 5:01 PM | 3.12 | 0 | 0 | 0 |
| Conner | Sarah | 1/7/2025 | 7:29 AM | 1/7/2025 | 12:43 PM | 5.23 | 8.53 | 0 | 8.53 |
| Conner | Sarah | 1/7/2025 | 1:43 PM | 1/7/2025 | 5:01 PM | 3.3 | 0 | 0 | 0 |
Hi MRM_CCM , is this what you are looking for? I'll just attach the images of the output and code the used. Thanks!
Here's the code:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Lastname", type text}, {"Firstname", type text}, {"InPunchDate", type datetime}, {"InPunchTime", type time}, {"OutPunchDate", type datetime}, {"OutPunchTime", type time}, {"EarnHours", type number}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Lastname", "Firstname", "InPunchDate", "OutPunchDate"}, {{"All", each _},{"Sum", each List.Sum(_[EarnHours])}})[[All],[Sum]],
Try1 = Table.AddColumn(#"Grouped Rows","RowCount", each Table.RowCount(_[All]) - 1),
Try2 = Table.AddColumn(Try1,"List", each {1.._[RowCount]}),
Try3 = Table.TransformColumns(Try2,{"List", each List.Transform(_, each 0)}),
#"Expanded List" = Table.ExpandListColumn(Try3, "List"),
SumNos = List.RemoveNulls(List.Combine(List.Zip({#"Expanded List"[Sum],#"Expanded List"[List]}))),
#"Expanded All" = Table.ExpandTableColumn(#"Expanded List"[[All]], "All", {"Lastname", "Firstname", "InPunchDate", "InPunchTime", "OutPunchDate", "OutPunchTime", "EarnHours"}, {"Lastname", "Firstname", "InPunchDate", "InPunchTime", "OutPunchDate", "OutPunchTime", "EarnHours"}),
FinTable = Table.TransformColumns(Table.AddIndexColumn(#"Expanded All","H3",0,1), {"H3", each SumNos{_}})
in
FinTable
- MRM_CCM1 year agoRegular Visitor
I;ve got a long way to go before I inderstand all of what you have going on there, but I was able to patch it into my query and it worked out great. Thankyou very much.