Can you please add more details about how you are calculating the sub hierarchies value as 9 for A_B?
A_B has 9 values because A_B's sub hierarchy which is
A _B_J *
A _B_K *
9 distinct values, in other words field Hierarchy_1=A and Hierarchy_2=B, I need to count distinct value for Hierarchy_3,
for each Hierarchy to cal its sub hierarchies' distinct value.
I hope you could get the basic idea.