Forum Discussion
wiselyman3
1 year agoHelper II
Merge Rows For Specific Date and Person, keeping first Log In and Last Log Out in the merged row
Hi everyone, I will do my best to explain this problem I need help with in PowerQuery/PowerBI. I have a table structured like this below: Name Log In Log Out Mike 1/27/2025 7:56:00...
- 1 year ago
Hi wiselyman3
First add a date only column.
Use the Group by feature in the query editor.
Here's the full M code
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdExDoMwDAXQq6DMSNgOboI3DoDEjhgZqvYAPX5T1W1jEUjXnzxH/lkWN11vm2sddhQ6AuImCF8EoBknEyMIsuZrW3DpQhlSCl/5fARJeNALed6LL7v4Po869/NerLDhu59hGlOFkbLZMhbPGRvv28MsEQ9KQdvmzqVSEAqlsC3z585L8Xa7HcvG5nGosD++YH0C", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, #"Log In" = _t, #"Log Out" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Log In", type datetime}, {"Log Out", type datetime}}, "en-us"), #"Inserted Date" = Table.AddColumn(#"Changed Type", "Date", each DateTime.Date([Log In]), type date), #"Grouped Rows" = Table.Group(#"Inserted Date", {"Name", "Date"}, {{"First Login", each List.Min([Log In]), type nullable datetime}, {"Last Logout", each List.Max([Log Out]), type nullable datetime}}) in #"Grouped Rows"
danextian
1 year agoSuper User
Hi wiselyman3
First add a date only column.
Use the Group by feature in the query editor.
Here's the full M code
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdExDoMwDAXQq6DMSNgOboI3DoDEjhgZqvYAPX5T1W1jEUjXnzxH/lkWN11vm2sddhQ6AuImCF8EoBknEyMIsuZrW3DpQhlSCl/5fARJeNALed6LL7v4Po869/NerLDhu59hGlOFkbLZMhbPGRvv28MsEQ9KQdvmzqVSEAqlsC3z585L8Xa7HcvG5nGosD++YH0C", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, #"Log In" = _t, #"Log Out" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Log In", type datetime}, {"Log Out", type datetime}}, "en-us"),
#"Inserted Date" = Table.AddColumn(#"Changed Type", "Date", each DateTime.Date([Log In]), type date),
#"Grouped Rows" = Table.Group(#"Inserted Date", {"Name", "Date"}, {{"First Login", each List.Min([Log In]), type nullable datetime}, {"Last Logout", each List.Max([Log Out]), type nullable datetime}})
in
#"Grouped Rows"
- wiselyman31 year agoHelper II
Thank you! This worked perfectly