Forum Discussion
klehar
Helper V
1 year agoTop 2 for each date
Hi This is my data Here for each date, I want the top 2 sales numbers 16 and 14 for 1/1 17 and 15 for 2/1 How can i do this in M code/query editor?
- 1 year ago
Hi klehar ,
How about this?
Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDUBSIjAyNTJR0lQzOlWB10MRMsYkZYxAwgYkbIYuZYxEyxiBljETNUio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [date = _t, sales = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"date", type date}, {"sales", Int64.Type}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"date"}, {{"TopSales", each Table.FirstN( Table.Sort(_, {{"sales", Order.Descending}}), 2 ), type table [sales=Int64.Type]}}), #"Expanded TopSales" = Table.ExpandTableColumn(#"Grouped Rows", "TopSales", {"sales"}, {"TopSales.sales"}) in #"Expanded TopSales"
/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/
Anonymous
1 year agoNot applicable
Hi klehar ,
Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or Accept the helpful suggestions to help others who faced similar requirements.
If these also don't help, please share more detailed information and description to help us clarify your scenario to test.
How to Get Your Question Answered Quickly
Regards,
Xiaoxin Sheng