Multi Level Account Hierarchy | Visualizing entire hierarchy
Recently I collaborated with Salesforce Blogger on a blog regarding reporting on Multi Level Hierarchy called Multi-Level Account Hierarchy: Flatten, Aggregate, Join, Transform and Report and this approach works perfectly if you wish to Aggregate metrics such as the no. of Accounts under the Ultimate Parent OR the no. of Opportunities under each parent and visualize these metrics in a dashboard OR if we wish to filter in a dashboard.
However, if you wish to visualize the entire hierarchy in a Table similar to the screenshot below, we will need a different approach, where we bring in all the Accounts from the Hierarchy Path.
Before I walk you through the steps, I put together a quick video explaining what we are trying to accomplish:
Now, let’s walk through the steps in order to accomplish the table above…
STEP 1: Flatten Your Hierarchy
Bring in your Account object and Flatten it. Again, the reason we want to flatten is that we want to be able to find the path upwards in the hierarchy.
Now, when we flatten we will automatically create 2 fields: 1) hierarchy multi value field which is a list of all ancestors for each node in the hierarchy as well as 2) hierarchy path which will show the hierarchy starting with the parent ID, and all the way to the to top to ultimate parent ID.
STEP 2: Calculate how many levels you have in your hierarchy
Now, what do we do with these two fields that were calculated for us? We can leverage Split and Size functions as explained below:
First, we wil look at the Hierarchy Multi field, and if this is null then it means we are at Level 0, if not, then we will use the the new Size function (highlighted in this Blog) to return the number of elements in a multivalue! This will tell us if our Path contains 3,4,5 or more accounts!
STEP 3: Extract your Accounts from the Multivalue field using Split transformation
One of the fields created will be a multivalue output column that contains a list of all ancestors on the hierarchy separated by a backlash which we will be able to separate with a Split transformation which splits the value at the first occurrence of the delimiter. In this case, our delimiter is a backlash \ This blog has more information on the split transformation: Split a multi value field:
The key in this step is to continue using the Split function to separate the string until you have no values left. So if you have 5 Accounts on the path, we would then use split 5 times.
First Split
Second Split
Third Split
Fourth Split
Fifth Split
STEP 4: Drop unnecessary columns
Now, you can also drop columns, . since we don’t need the original column and every split transformation 2nd split column that we split, add the Drop Columns transformation after the Split transformation to drop it from the recipe. From that point, the original column doesn’t appear in Preview and it won’t show up once we run our recipe.
STEP 5: Test your splits in a lens before augmenting
STEP 6: Augment to bring in Account Name
Augment bringing in Account multiple times, until you have the Account Name for all of the Accounts in your Path, your recipe will look similar to the recipe below:
First Join
Second Join
Third Join
Fourth Join
Now once you are done joining your Account, it’s time to run the recipe and test!
STEP 7: Test your final dataset in a lens
Now, if you just want to roll-up metrics all the way to the Ultimate Parent, I recommend you follow the steps on the original blog: Multi-level Account Hierarchy: Flatten Aggregate, Join, Transform and Report. Keep in mind you can always create 2 datasets: 1. Following the original blog where you aggregate metrics under Ultimate Parent, 2. The dataset described in this blog and then use BOTH datasets in a dashboard and just make sure you connect the data sources.
Hope this was helpful!