Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
arutsjak90
Helper I
Helper I

Create top 2 table per category with sku

HI, I am trying to create new table with top2 values per category. 

 

CategorySKUQTy
A110
A25
A315
A42
B56
B67
B79
C812
C97

 

Expected result (new table)

CategorySKUQTy
A315
A110
B79
B67
C812
C79

 

Is it possible to create in Power BI, it is important for me to have new table.

Thank you in advance!

1 ACCEPTED 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.

View solution in original post

3 REPLIES 3
Vera_33
Resident Rockstar
Resident Rockstar

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"

 

Vera_33_0-1615440188127.png

 

 

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.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.