Hey team!
I'm working with some hierarchical data output from our ERP system's vanilla reporting software and my finance team wants a low maintenance excel spreadsheet that identifies all of the levels of a hierarchy as attributes / dimensions. Our hierarchies are built as parent/child combos, not as attribute/level rolls ups, so we don't really have a table that's stored with each individual level of the hierarchy for each GL account.
I would love to land on a formula that I can use to identify the levels of the hierarchy for each GL. The report outputs the hierarchy cascading with the hierarchy nodes below each GL account. The nodes are identified with leading asterisk characters (I know, that makes things a little more challenging), that increase in quantity as we get closer to the top of the hierarchy.
Here's an example of what the report spits out:
[TABLE="class: grid, width: 200"]
<tbody>[TR]
[TD][/TD]
[TD="align: center"]A[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: center"]Hierarchy[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]GL1[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]GL2[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]GL3[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]***Gross Slaes[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]GL4[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]GL5[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]***Discounts[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]****Net Sales[/TD]
[/TR]
</tbody>[/TABLE]
What I am working towards is this:
[TABLE="class: grid, width: 600"]
<tbody>[TR]
[TD][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: center"]Hierarchy[/TD]
[TD="align: center"]Level 1[/TD]
[TD="align: center"]Level 2[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]GL1[/TD]
[TD]***Gross Sales[/TD]
[TD]****Net Sales[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]GL2[/TD]
[TD]***Gross Sales[/TD]
[TD]****Net Sales[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]GL3[/TD]
[TD]***Gross Sales[/TD]
[TD]****Net Sales[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]***Gross Sales[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]GL4[/TD]
[TD]***Discounts[/TD]
[TD]****Net Sales[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]GL5[/TD]
[TD]***Discounts[/TD]
[TD]****Net Sales[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]***Discounts[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]****Net Sales[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Level 1 is relatively simple, I just needed to find the next value with an "*", or the parent to the GL accounts. I used a formula like this (note, I'm trimming everything because my actual data has a ton of unneeded spaces):
=IF(LEFT(TRIM($A2),2)="GL",INDEX($A2:$A$8,MATCH("~*",LEFT(TRIM($A2:$A$8),1),0),),"")
Level 2, however, I think I need to find the length of "*"s in a cell, then find the next cell that's 1 "*" longer.
I know I can use a "len() - len(substitute)" formula to find how many "*"s there are, like this:
=LEN(TRIM($B2))-LEN(SUBSTITUTE(TRIM($B2),"*",""))
... and could add "+1" to this to know the number of "*" I need to lookup, but I'm at a loss for what formula to use now to find the next record with +1 "*"s from the value I've found.
I am hoping to figure this out with formulas as the maintenance for the eventual users will be much easier than a macro. The current hierarchy is 1,000 records long and there are 10 different levels in some places, so this would be a very tedious process to replicate manually whenever there are hierarchy updates.
Thanks in advance!!
I'm working with some hierarchical data output from our ERP system's vanilla reporting software and my finance team wants a low maintenance excel spreadsheet that identifies all of the levels of a hierarchy as attributes / dimensions. Our hierarchies are built as parent/child combos, not as attribute/level rolls ups, so we don't really have a table that's stored with each individual level of the hierarchy for each GL account.
I would love to land on a formula that I can use to identify the levels of the hierarchy for each GL. The report outputs the hierarchy cascading with the hierarchy nodes below each GL account. The nodes are identified with leading asterisk characters (I know, that makes things a little more challenging), that increase in quantity as we get closer to the top of the hierarchy.
Here's an example of what the report spits out:
[TABLE="class: grid, width: 200"]
<tbody>[TR]
[TD][/TD]
[TD="align: center"]A[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: center"]Hierarchy[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]GL1[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]GL2[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]GL3[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]***Gross Slaes[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]GL4[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]GL5[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]***Discounts[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]****Net Sales[/TD]
[/TR]
</tbody>[/TABLE]
What I am working towards is this:
[TABLE="class: grid, width: 600"]
<tbody>[TR]
[TD][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: center"]Hierarchy[/TD]
[TD="align: center"]Level 1[/TD]
[TD="align: center"]Level 2[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]GL1[/TD]
[TD]***Gross Sales[/TD]
[TD]****Net Sales[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]GL2[/TD]
[TD]***Gross Sales[/TD]
[TD]****Net Sales[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]GL3[/TD]
[TD]***Gross Sales[/TD]
[TD]****Net Sales[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]***Gross Sales[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]GL4[/TD]
[TD]***Discounts[/TD]
[TD]****Net Sales[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]GL5[/TD]
[TD]***Discounts[/TD]
[TD]****Net Sales[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]***Discounts[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]****Net Sales[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Level 1 is relatively simple, I just needed to find the next value with an "*", or the parent to the GL accounts. I used a formula like this (note, I'm trimming everything because my actual data has a ton of unneeded spaces):
=IF(LEFT(TRIM($A2),2)="GL",INDEX($A2:$A$8,MATCH("~*",LEFT(TRIM($A2:$A$8),1),0),),"")
Level 2, however, I think I need to find the length of "*"s in a cell, then find the next cell that's 1 "*" longer.
I know I can use a "len() - len(substitute)" formula to find how many "*"s there are, like this:
=LEN(TRIM($B2))-LEN(SUBSTITUTE(TRIM($B2),"*",""))
... and could add "+1" to this to know the number of "*" I need to lookup, but I'm at a loss for what formula to use now to find the next record with +1 "*"s from the value I've found.
I am hoping to figure this out with formulas as the maintenance for the eventual users will be much easier than a macro. The current hierarchy is 1,000 records long and there are 10 different levels in some places, so this would be a very tedious process to replicate manually whenever there are hierarchy updates.
Thanks in advance!!