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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
derekmac
Helper I
Helper I

Power Query Conditional Column Logic for Hierarchies

 

#"Added Custom" = Table.AddColumn(#"Removed Columns", "Level 1", each if [Manager4_Name]= null then [Manager3_Name] else [Manager4_Name]),
    #"Added Conditional Column" = Table.AddColumn(#"Added Custom", "Level1a", each if [Level 1] = null then [Manager2_Name] else [Level 1]),
    #"Added Conditional Column1" = Table.AddColumn(#"Added Conditional Column", "Level1b", each if [Level1a] = null then [Manager1_Name] else [Level1a]),
    #"Added Conditional Column2" = Table.AddColumn(#"Added Conditional Column1", "Level 1c", each if [Level1b] = null then [ReportingTo] else [Level1b])

 

Hi All
I have added 4 Steps above to create a Column with highest non null Value across 4 Columns

 

Manager4_Name     Manager3_Name   Manager2_Name Manager1_Name    ReportingTo

John Smith

null              David Smith     Pete Smith

                                                                                    
null              null            Rob Smith    Jackie Smith     Geraint Smith

 

I woul like to get

 

Level 1

John Smith
David Smith                                                                                    Rob Smith

 

My Steps above appear to achieve this, but can this be done in one Step? 


1 ACCEPTED SOLUTION

Hi @derekmac 

 

I suppose it will be a matter of adding a couple of "ifs". Try it: 

= Table.AddColumn(#"Removed Columns", "Level 2", each if [Manager4_Name]<>null then [Manager3_Name]??[Manager2_Name]??[Manager1_Name]??[#" ReportingTo"] else if [Manager3_Name]<>null then [Manager2_Name]??[Manager1_Name]??[#" ReportingTo"] else if [Manager2_Name]<>null then [Manager1_Name]??[#" ReportingTo"] else if [Manager1_Name]<>null then [#" ReportingTo"] else null)

 

View solution in original post

4 REPLIES 4
wdx223_Daniel
Super User
Super User

=List.Skip(Record.ToList(_),each _=null){0}?

=List.Skip(Record.ToList(_),each _=null){1}?

mlsx4
Memorable Member
Memorable Member

Hi @derekmac 

 

Yes, you can do it using this:

= Table.AddColumn(#"Removed Columns", "Level 1", each [Manager4_Name]??[Manager3_Name]??[Manager2_Name]??[Manager1_Name]??[#" ReportingTo"])

 

Thanks a lot

How would I replicate this for Level 2 so in the example above I get Pete Smith from the middle line? and Jackie Smith in the 3rd line?

Hi @derekmac 

 

I suppose it will be a matter of adding a couple of "ifs". Try it: 

= Table.AddColumn(#"Removed Columns", "Level 2", each if [Manager4_Name]<>null then [Manager3_Name]??[Manager2_Name]??[Manager1_Name]??[#" ReportingTo"] else if [Manager3_Name]<>null then [Manager2_Name]??[Manager1_Name]??[#" ReportingTo"] else if [Manager2_Name]<>null then [Manager1_Name]??[#" ReportingTo"] else if [Manager1_Name]<>null then [#" ReportingTo"] else null)

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.