Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Expanding Hierarchical Data

logical_pea_20
5 - Atom

Hi,

 

I am trying to take hierarchical data and expand it out for each "level" in the hierarchy based on a legend. My initial thought was to somehow run it through an iterative macro, counting down the level until I reach the bottom layer of the hierarchy. I am having some trouble wrapping my head around if this approach makes sense and how to append the entries together. Please see below an example of my data, my desired result, and my rough attempt at creating the workflow needed.

 

I would greatly appreciate any help or ideas on how to transform this data. Thanks.

 

Input data (simplified IDs for demonstration)

IDValueLevelImmediate_Parent
1-49141-3
2-65662-5

 

Desired result (simplified IDs for demonstration)

IDValueLevelImmediate_Parent
1-49141-3
1-39131-2
1-29121-1
1-1911 
2-65662-5
2-55652-4
2-45642-3
2-35632-2
2-25622-1
2-1561 

 

Attempt

logical_pea_20_1-1644374511379.png

 

 

4 REPLIES 4
apathetichell
18 - Pollux

I'd use generate rows to get a range. Regex to subtract a number from the second digit based upon the range count and to clean up the last value - and a multi-row formula to slot them down one.

 

Probably would need a select tool in practice to increase the size of the string field before the regex. I wouldn't recommend using an iterative macro for this.

Qiu
20 - Arcturus
20 - Arcturus

@logical_pea_20 
The solution provided by @apathetichell  is already perfect in my opinon and I only add one formula tool to set the top level immediate parent to null.

Capture1B.PNG

logical_pea_20
5 - Atom

Thanks for your response! I should have made this clearer but the actual IDs would be more complicated in practice with no reliable pattern to run a RegEx on. I just wanted to demonstrate the idea since the actuals IDs are more difficult to wrap one's head around. The difficulty I was having was searching through a hierarchy to replace the ID and Immediate_Parent values.

 

In practice the IDs would look like this:

IDValueLevelImmediate_Parent
130100000914130000000
110000000566100000000

 

And the legend would be like this:

IDLevelImmediate_Parent
0000000001 
2100000002000000000
2300000003210000000
2301000004230000000
0000000001 
2100000002000000000
2300000003210000000
2302000004230000000
1000000005230200000
1100000006100000000


The desired result would be the same (with more complicated IDs):

IDValueLevelImmediate_Parent
230100000914230000000
230000000913210000000
210000000912000000000
000000000911 
110000000566100000000
100000000565230200000
230200000564230000000
230000000563210000000
210000000562000000000
000000000561 

 

In this case, would it make sense to run the data through a macro?

apathetichell
18 - Pollux

Yes. - that's more of an iterative macro. The existence of a 1-1 match in a legend changes this entire process. The way how you described it originally the rows were built out via an internal category (the range). Having the rows preexisting and with a unique set of values makes this a bit different. Note - if you had a key like you do in the first - with a numeric value which is static, I might recommend some combo of tile tool self-join.

Labels