Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Mario1000
Advocate I
Advocate I

Hierarchy with same child name for different parents

Hi,

I'm working with a parent-child hierarchy but in which some child values have different parents. For instance:

ChildParent
USACountry
FranceCountry
RevenuesUSA
RevenuesFrance

 

The hierarchy function PATH() does not support a hierarchy like that with same child for different parents. Is there any way to work with this kind of hierarchy?

 

Thanks!

1 ACCEPTED SOLUTION

@Mario1000 

 

Try this custom Column from Query Editor

 

=let //Define your columns below
 c=[Child],p=[Parent],mytable=#"Changed Type",pc="Parent",cc="Child" 
  in
let mylist={c} & List.Generate(()=>[x=0,y=p,w=1],each [w] > 0,each [z=[y], 
x=Table.Column(Table.SelectRows(mytable,each Record.Field(_,cc)=z),pc),y=x{0},w=List.Count(x)
],
each [y])
        in
Text.Combine(List.Reverse(List.RemoveItems(
List.Transform(mylist,each Text.From(_)),{null,""})),"|")

pth.png


Regards
Zubair

Please try my custom visuals

View solution in original post

3 REPLIES 3
kentyler
Solution Sage
Solution Sage

   
countryUSARevenues
CountryFranceRevenues

recast your hierarchy, the parent "country" has 2 children, "USA" and "France", each of them has one child "Revenues"





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


Yes, that's the hierarchy of the example. But now imagine that you have a table of thousands of rows instead of just 4. Then to build up the hierarchy you would use the PATH( <ID_ColumnName>, <Parent_ColumnName>) function, but this function 

returns an error if parent_columnName value is different for those duplicates  (which is the case).

 

Then my question was, how to build the hierarchy anyway? I'm afraid it's not possible...

@Mario1000 

 

Try this custom Column from Query Editor

 

=let //Define your columns below
 c=[Child],p=[Parent],mytable=#"Changed Type",pc="Parent",cc="Child" 
  in
let mylist={c} & List.Generate(()=>[x=0,y=p,w=1],each [w] > 0,each [z=[y], 
x=Table.Column(Table.SelectRows(mytable,each Record.Field(_,cc)=z),pc),y=x{0},w=List.Count(x)
],
each [y])
        in
Text.Combine(List.Reverse(List.RemoveItems(
List.Transform(mylist,each Text.From(_)),{null,""})),"|")

pth.png


Regards
Zubair

Please try my custom visuals

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors