Nested grouping of hierarchical items with Power Query

Guitarmageddon

Board Regular
Joined
Dec 22, 2014
Messages
161
**Title should read "Nested RANKING of hierarchical items**

Hello folks. I have some sales data that I cleaned up and grouped with power query. It distinct styles, and is sorted by a few levels of my hierarchy. You can see a snip below.

Department contains classes, contains sublcasses, contains the style number/description (1:1). I am summarizing the "ADD TTL" column which is just a demand/sales number.

I am trying to figure out how to rank the ADD TTL column just as you see below, within the SUBCLASS column. I cant quite figure this one out. I put in some crude examples over on the right of how I would expect this to look as the final product.

group help.png


I started messing with Table.AddRankColumn but I think Im missing a piece. Because when I insert that after the step above, it throws the entire sort out of whack, as you can see. None of the original groupings are chunked out together and it just sorts the entire output by that "ADD TTL" column. Thoughts?

1679501739821.png
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
I suggest indicating what version of Excel you're using and on which OS, and using XL2BB to post data.
Much too difficult to transcribe even a little bit of that.
 
Upvote 0
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
    #"Grouped Rows" = Table.Group(#"Added Index", {"Category"}, {{"All", each Table.AddRankColumn(_, "LocalRank", {"Value", Order.Descending})}},0),
    #"Expanded All" = Table.ExpandTableColumn(#"Grouped Rows", "All", {"ID", "Value", "LocalRank", "Index"}),
    #"Sorted Rows" = Table.Sort(#"Expanded All",{{"Index", Order.Ascending}}),
    #"Removed Columns" = Table.RemoveColumns(#"Sorted Rows",{"Index"})
in
    #"Removed Columns"

Book2
ABCDEFGHI
1CategoryIDValueCategoryIDValueLocalRank
2A6150.84A6150.843
3A12201.12A12201.122
4A1887.99A1887.995
5A5213.69A5213.691
6A16113.13A16113.134
7B17226.26B17226.261
8B1175.42B1175.427
9B8125.7B8125.75
10B1362.85B1362.858
11B10163.41B10163.413
12B3100.56B3100.566
13B19188.55B19188.552
14B750.28B750.289
15B2138.27B2138.274
16C912.57C912.575
17C1175.98C1175.982
18C15238.83C15238.831
19C1437.71C1437.713
20C425.14C425.144
21
Sheet2
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,123
Members
452,381
Latest member
Nova88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top