Forum Discussion
tom1tas
3 years agoFrequent Visitor
Obtaining unique values based on a given condition
Hello Everyone, I currently have a query that contains data from hours reported towards different companies in 2022-2023 organized on a daily date format. Therefore for each day, I have a split of ...
adudani
3 years agoMemorable Member
hi tom1tas ,
create a blank query and in the advanced editor , copy paste the following code:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVtJRckrMA8Ji5/zcgsS8SqCAORAb6Rua6BsZGBkpxerAFIJUlJakFiEpNSSkVAGh1gyi1hRdLdR+BQxTMVSWJwKNxK0uFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Employee ID" = _t, Company = _t, #"Working Hours" = _t, Date = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Employee ID", Int64.Type}, {"Company", type text}, {"Working Hours", Int64.Type}, {"Date", type date}}),
#"Grouped Rows by Employee and Date" = Table.Group(#"Changed Type", {"Employee ID", "Date"}, {{"Details", each _, type table [Employee ID=nullable number, Company=nullable text, Working Hours=nullable number, Date=nullable date]}}),
#"Added Index Column in the Details Column" = Table.AddColumn(#"Grouped Rows by Employee and Date", "Custom", each Table.AddIndexColumn([Details],"Index")),
#"Expanded Custom" = Table.ExpandTableColumn(#"Added Index Column in the Details Column", "Custom", {"Company", "Index"}, {"Company", "Index"}),
#"Take Value with Most hours worked" = Table.SelectRows(#"Expanded Custom", each ([Index] = 0)),
#"Removed Columns" = Table.RemoveColumns(#"Take Value with Most hours worked",{"Details", "Index"})
in
#"Removed Columns"
tom1tas
3 years agoFrequent Visitor
Can you explain it as query steps? I used dummy data therefore it does not work for me to get m code solutions