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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

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
Super User
Super User

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
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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

Top Solution Authors