Forum Discussion
Berl21
Helper III
4 years agoCalculated column with the max per group
I need to add a column in my query that would show the max of an index column per group. This is how it currently looks like into the tool: In this case, there are two groups, t...
Vijay_A_Verma
Most Valuable Professional
4 years agoSee the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately. If you have columns other than these, then delete Changed type step and do a Changed type for complete table from UI again)
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Xc+xDQAhDATBXhyDZBsMfC2I/tv4k0g4pxPt7i2u7lVX1SFFTE55aIKcaYEa0wfqRKagYDLQYHLQZGqg9VBUtdQF8tQFaqkL1FMXKFJX3O3BNG/X+QE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Rank = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Rank", Int64.Type}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
#"Added Custom" = Table.AddColumn(#"Added Index", "Highest Rank in a Group", each try if #"Added Index"[Rank]{[Index]+1}<[Rank] then [Rank] else null otherwise [Rank], Int64.Type),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"}),
#"Filled Up" = Table.FillUp(#"Removed Columns",{"Highest Rank in a Group"})
in
#"Filled Up"
👍 It's been a pleasure to help you | Help Hours: 11 AM to 9 PM (UTC+05:30)
How to get your questions answered quickly -- How to provide sample data