Sum Hierarchy Data Using Flattened Hierarchy

neb255

Board Regular
Joined
Sep 14, 2011
Messages
64
Excel 365 for Enterprise -- I have access to LET, and Xlookup etc.

Hi,
I am trying to create a rollup of data using an unsorted collapsed hierarchy, by which I mean that the parent child relationships do not follow each other in the spreadsheet so I cannot just take the sum of rows above or below the current row.

The example Hierarchy has 6 people in it which looks like this
  1. Arnold
    1. Mike
    2. Anthony
      1. Bill
        1. John
        2. Alex
The underlying data has the the "Rep" listed as anyone who has a value directly associated with their name, and their direct "Manager" and looks like the below.

Underlying Data
ABCDEFGHIJKLMNO
2ManagerRepJanFebMarAprMayJunJulAugSeptOctNovDecFY
3BillJohn1382651782408242301264693496414638384,761
4BillAlex1581446518462823661771017647451147885,136
5AnthonyBill8127281078995561822037887217407684676,971
6BillJohn92177119160549153843132334273095593,174
7ArnoldMike1059643456418824411867509497765253,424
8Total1,3051,4101,4892,7092,3991,1757081,7382,5763,0501,7303,17723,466

What I need to do is create a rollup by rep, rep to manager, rep to manager to manager in a second table. So in this case, anything which sits with John or Alex would roll up to Bill, and Bill would show his own records added to the rollup from John and Alex. Then since Anthony does not have anything directly in his name would get the rollup from Bill which already includes the rollup from John and Alex. Likewise Arnold would receive the rollup from Mike who has direct numbers and Anthony who has the rollup of Bill, John, and Alex. Which should look like this:
ABCDEFGHIJKLMNO
ManagerRepJanFebMarAprMayJunJulAugSeptOctNovDecFY
11BillAlex1581446518462823661771017647451147885,136
12ArnoldAnthony1,2001,3141,0552,1452,2119315901,6712,0672,5531,6542,65220,042
13Arnold1,3051,4101,4892,7092,3991,1757081,7382,5763,0501,7303,17723,466
14AnthonyBill1,2001,3141,0552,1452,2119315901,6712,0672,5531,6542,65220,042
15BillJohn2304422974001,3733832107825821,0687721,3977,935
16JohnMike1059643456418824411867509497765253,424

The formula I am currently using (in cell C11) is =SUMIFS(C$3:C$7,$A$3:$A$7,$B11)+SUMIFS(C$3:C$7,$B$3:$B$7,$B11) which takes the sum of the top table in column C if the Rep name is the same as the rep name in table two column B, then adds the sum of the top table if the Rep also appears as a Manager

The problem I am having is that this formula does not return the correct response for Arnold or Anthony since in the top table Arnold would only return Mike and Anthony would only return Bill's so their result would look like this:
ManagerRepJanFebMarAprMayJunJulAugSeptOctNovDecFY
ArnoldAnthony8127281078995561822037887217407684676,971
Arnold1059643456418824411867509497765253,424
I have also tried adding an additional sumif to the 2nd table to add the value if the "Rep" also appears as a manager in it +SUMIFS(C$11:C$16,$A$11:$A$16,B12) but this creates a circular reference which double counts for any managers who appear in the top table.

The format of the 2 tables here are fixed and cannot be changed, and the actual hierarchy can range anywhere from 2 to 6 layers deep and is a few hundred individuals. We are also using unique identifiers instead of names so there is no risk of duplication from that respect. The reason I am using SUMIFS instead of SUMIF is that in the full dataset we are also cutting the data by a few other categories.

What I need is a way to recognize in the second table that Anthony's numbers need to roll up not just Bill but also Bill's reports John and Alex. And that Arnold should roll up from Anthony and Mike. Without double counting the amounts which were already rolled up to the "middle managers." In theory I could create a separate table for every single tier of management but that would become impossible to maintain over time. I am open to Power Query or VBA responses as well, however calculation speed is an issue since there are approximately 75k cells which will have the formula in it so array's are a no-no.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
I should also note, that since not all "Reps" from the first table will appear in the second table, the Manager rollup needs to be sourced from the first table otherwise it could end up with a reduced value.

Also in second table Mike should report to Arnold not John.
16ArnoldMike1059643456418824411867509497765253,424
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,121
Members
453,021
Latest member
Justyna P

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