Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
HI, I am trying to create new table with top2 values per category.
Category | SKU | QTy |
A | 1 | 10 |
A | 2 | 5 |
A | 3 | 15 |
A | 4 | 2 |
B | 5 | 6 |
B | 6 | 7 |
B | 7 | 9 |
C | 8 | 12 |
C | 9 | 7 |
Expected result (new table)
Category | SKU | QTy |
A | 3 | 15 |
A | 1 | 10 |
B | 7 | 9 |
B | 6 | 7 |
C | 8 | 12 |
C | 7 | 9 |
Is it possible to create in Power BI, it is important for me to have new table.
Thank you in advance!
Solved! Go to Solution.
OK, resolved. I have created new column using rankx, then I have created new table using CALCULATE TABLE (SUMMARIZE(), RANK <3). Thank you for your help.
Hi @arutsjak90
How do you like, DAX calculated table or Power Query? Here is a way in M, paste in Advanced Editor
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIEYQOlWB0I1wiITeE8Y5AkgmsCVgDiOYGV6SiZwXlmQGwO55kDsSWY5wxkWYCMMYJzLSFKYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t, SKU = _t, QTy = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"SKU", Int64.Type}, {"QTy", Int64.Type}}),
#"Sorted Rows" = Table.Sort(#"Changed Type",{{"Category", Order.Ascending}, {"QTy", Order.Descending}}),
#"Grouped Rows" = Table.Group(#"Sorted Rows", {"Category"}, {{"allrows", each _, type table [Category=nullable text, SKU=nullable number, QTy=nullable number]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.FirstN([allrows],2)),
#"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
#"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Category", "SKU", "QTy"}, {"Category", "SKU", "QTy"})
in
#"Expanded Custom"
HI Vera_33, thank you for your hard work! 😊 I'am not sure and I didn't mention that but if my current table is a calculated table (summarize) then I can not use it in M? If so, dax is a only way, ofc in my beginner opinion.
OK, resolved. I have created new column using rankx, then I have created new table using CALCULATE TABLE (SUMMARIZE(), RANK <3). Thank you for your help.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
112 | |
99 | |
73 | |
72 | |
49 |
User | Count |
---|---|
145 | |
109 | |
108 | |
90 | |
64 |