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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
montibellin
Helper I
Helper I

power query hierarchy's calculation

Hi Guys,

I'm searching a method to calculate in an additional column the hierarchy on column1 based on the parent relationship reported in column2. 
Basically the root level is Leve1 when "location" is reported on Column2.
below a picture that shown what I need

montibellin_0-1667750713046.png

 

1 ACCEPTED SOLUTION

it works only in this case, when the values don't change. Otherwise I need to update code every time.

I'm found a solution using Merge funciton applied on the same table.

montibellin_0-1667773774646.png

in the result it's necessary to select "lev 1", that can be renamed in "lev 2", then filter "lev 0" = "location"
this is the result

montibellin_1-1667773923719.png

 

 

View solution in original post

4 REPLIES 4
mangaus1111
Solution Sage
Solution Sage

Hi @montibellin ,

try this 

= Table.AddColumn(#"Changed Type", "Custom", each if [Parent] = "Location" then "Level 1" else if [Parent] = "Europe" or [Parent] = "Africa" or [Parent] = "Oceania" or [Parent] = "Asia" or [Parent] = "America" then "Level 2" else "Level 3")

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

it works only in this case, when the values don't change. Otherwise I need to update code every time.

I'm found a solution using Merge funciton applied on the same table.

montibellin_0-1667773774646.png

in the result it's necessary to select "lev 1", that can be renamed in "lev 2", then filter "lev 0" = "location"
this is the result

montibellin_1-1667773923719.png

 

 

mangaus1111
Solution Sage
Solution Sage

Hi @montibellin ,

you can use this calculated column

mangaus1111_0-1667764066109.png

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks Mangus but I have to do this in Power Query editor

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.