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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Honne2021
Helper II
Helper II

Hierarchy Levels

Hi, I have a data that looks like this with thousand of rows and I need to know how many levels does each employee has to get to Person Z. In this example, the answer for Joon should be 4 as there are 4 persons to reach Person Z. Kook should be 1. 

 

EmployeeLevel 1Level 2Level 3Level 4Level 5Level 6Level 7Level 8
JoonPerson APerson BPerson HPerson YPerson Z   
KookPerson FPerson Z      



Thank you in advance

2 ACCEPTED SOLUTIONS
Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Put following formula in a custom column

= List.PositionOf(Record.ToList(_),"Person Z")-1

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8srPz1PSUQpILSrOz1NwRDCdEEwPBDMSwYwCMqEoVidayTs/Pxsh6YZVHUJDLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Employee = _t, #"Level 1" = _t, #"Level 2" = _t, #"Level 3" = _t, #"Level 4" = _t, #"Level 5" = _t, #"Level 6" = _t, #"Level 7" = _t, #"Level 8" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Level", each List.PositionOf(Record.ToList(_),"Person Z")-1, Int64.Type)
in
    #"Added Custom"

 

View solution in original post

Hmm it seems to count the second Person Z. I just changed the formula to -2 instead of -1. I appreciate your quick assistance. 

= List.PositionOf(Record.ToList(_),"Person Z")-1

 

View solution in original post

4 REPLIES 4
Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Put following formula in a custom column

= List.PositionOf(Record.ToList(_),"Person Z")-1

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8srPz1PSUQpILSrOz1NwRDCdEEwPBDMSwYwCMqEoVidayTs/Pxsh6YZVHUJDLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Employee = _t, #"Level 1" = _t, #"Level 2" = _t, #"Level 3" = _t, #"Level 4" = _t, #"Level 5" = _t, #"Level 6" = _t, #"Level 7" = _t, #"Level 8" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Level", each List.PositionOf(Record.ToList(_),"Person Z")-1, Int64.Type)
in
    #"Added Custom"

 

Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

It will take the first Person Z only not any other. 

Hmm it seems to count the second Person Z. I just changed the formula to -2 instead of -1. I appreciate your quick assistance. 

= List.PositionOf(Record.ToList(_),"Person Z")-1

 

Hi. Sorry I forgot to mention that there are instances where in Person Z is in two columns like this. What formula should I add so that only the first Person Z is counted. Hence Kook should be 1 instead of 2.

EmployeeLevel 1Level 2Level 3Level 4...until Level 20
KookPerson FPerson ZPerson Z  


Thank you for your help!

Helpful resources

Announcements
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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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