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

Move Values to the Left in Columns Side by Sides, removing Nulls

Hi All

 

I have a set of fields as below

 

Manager4_NameManager3_NameManager2_NameManager1_NameReportingToFullname
nullnullnullnullJane UptonNicole Peters
nullnullnullAaron JohnAaron JohnJan Orchard
nullnullAaron JohnPam ClementPam ClementElliot Paul
nullAdam JohnsonAnna KournikovaAdiam AhmadAdiam AhmadAzir Mohamed
Darren JonesAlan PatelPaul SmithAlan SmithAlan SmithAlexandra Inniss

 

I would like to change this to the following format in Power Query

 

Manager4_NameManager3_NameManager2_NameManager1_NameReportingToFullname
Jane UptonNicole Peters    
Aaron JohnAaron JohnJan Orchard   
Aaron JohnPam ClementPam ClementElliot Paul  
Adam JohnsonAnna KournikovaAdiam AhmadAdiam AhmadAzir Mohamed 
Darren JonesAlan PatelPaul SmithAlan SmithAlan Smith

Alexandra Inniss

 

So basically remove all Nulls and move the values across so line up the levels

All help appreciated!

1 ACCEPTED SOLUTION

let
    Source = your_table,
    to_rows = List.Buffer(Table.ToRows(Source)),
    count = Table.ColumnCount(Source) - 1,
    txform = List.Transform(
        to_rows, 
        (x) => 
            [a = List.RemoveNulls(List.RemoveLastN(x, 1)),
            b = a & List.Repeat({null}, count - List.Count(a)) & {List.Last(x)}][b]
    ),
    z = Table.FromRows(txform, Table.ColumnNames(Source))
in
    z

View solution in original post

6 REPLIES 6
mlsx4
Memorable Member
Memorable Member

Hi @derekmac 

 

Add this step from your last step (remember to replace #"Headers promoted" by the name of your last step):

 

 

= Table.ReverseRows(Table.FromRecords(List.Transform(List.Reverse(List.Transform(Table.ToRows(#"Headers promoted"),List.RemoveNulls)),each Record.FromList(_,List.FirstN(Table.ColumnNames(#"Headers promoted"),List.Count(_)))),null,MissingField.UseNull))

 

 

 

Thank you

AlienSx
Super User
Super User

Hello, @derekmac 

let
    Source = your_table,
    to_rows = List.Buffer(Table.ToRows(Source)),
    count = Table.ColumnCount(Source),
    txform = List.Transform(
        to_rows, 
        (x) => 
            [a = List.RemoveNulls(x),
            b = a & List.Repeat({null}, count - List.Count(a))][b]
    ),
    z = Table.FromRows(txform, Table.ColumnNames(Source))
in
    z

Thanks a Lot

 

Manager4_NameManager3_NameManager2_NameManager1_NameReportingToFullnameID
nullnullnullnullJane UptonNicole Peters1
nullnullnullAaron JohnAaron JohnJan Orchard2
nullnullAaron JohnPam ClementPam ClementElliot Paul3
nullAdam JohnsonAnna KournikovaAdiam AhmadAdiam AhmadAzir Mohamed4
Darren JonesAlan PatelPaul SmithAlan SmithAlan SmithAlexandra Inniss5

 

I omitted the ID Column which I would like to stay where it is, is that possible?

 

Manager4_NameManager3_NameManager2_NameManager1_NameReportingToFullnameID
Jane UptonNicole Peters    1
Aaron JohnAaron JohnJan Orchard   2
Aaron JohnPam ClementPam ClementElliot Paul  3
Adam JohnsonAnna KournikovaAdiam AhmadAdiam AhmadAzir Mohamed 4
Darren JonesAlan PatelPaul SmithAlan SmithAlan Smith

Alexandra Inniss

5

let
    Source = your_table,
    to_rows = List.Buffer(Table.ToRows(Source)),
    count = Table.ColumnCount(Source) - 1,
    txform = List.Transform(
        to_rows, 
        (x) => 
            [a = List.RemoveNulls(List.RemoveLastN(x, 1)),
            b = a & List.Repeat({null}, count - List.Count(a)) & {List.Last(x)}][b]
    ),
    z = Table.FromRows(txform, Table.ColumnNames(Source))
in
    z

Thanks a lot

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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.