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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Einomi
Helper V
Helper V

Shift Values to the Left for certain rows

Hi All,

 

I pulled out some data from a PDF and as expected not all data are well presented. My issues is that I have sometimes blank columns and all the data moved to the right. I need to get some data shifted to the left, I have tried unpivot but did not work for me

 

Here is the screenshot

 

Untitled.png

 

let
    Source = Pdf.Tables(File.Contents("C:\XXXX\XXXX\XXXX\Storage 12.12.22 - 289775.pdf"), [Implementation="1.3"]),
    #"Lignes filtrées" = Table.SelectRows(Source, each ([Kind] = "Page")),
    #"Data développé" = Table.ExpandTableColumn(#"Lignes filtrées", "Data", {"Column1", "Column2", "Column3", "Column4", "Column5", "Column6", "Column7", "Column8", "Column9", "Column10", "Column11"}, {"Data.Column1", "Data.Column2", "Data.Column3", "Data.Column4", "Data.Column5", "Data.Column6", "Data.Column7", "Data.Column8", "Data.Column9", "Data.Column10", "Data.Column11"}),
    #"Colonnes supprimées" = Table.RemoveColumns(#"Data développé",{"Id", "Name", "Kind", "Data.Column1"}),
    #"Lignes filtrées1" = Table.SelectRows(#"Colonnes supprimées", each ([Data.Column2] <> null and [Data.Column2] <> "Card Payments :" and [Data.Column2] <> "M3 7BB" and [Data.Column2] <> "Part No" and [Data.Column2] <> "SALFORD")),
    #"Colonnes supprimées2" = Table.RemoveColumns(#"Lignes filtrées1",{"Data.Column4", "Data.Column5"})
in
    #"Colonnes supprimées2"

Here is my M code 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Einomi ,

 

Suppose we have:

vcgaomsft_1-1672812218949.png

You may consider creating three new conditional columns. like this:

= if [Data.Column6] = null then [Data.Column7] else [Data.Column6]
= if [Data.Column6] = null then [Data.Column8] else [Data.Column7]
= if [Data.Column6] = null then null else [Data.Column8]

Then remove and rename the columns.

vcgaomsft_2-1672812329970.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTICYmOlWJ1oJQQnFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data.Column6 = _t, Data.Column7 = _t, Data.Column8 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Data.Column6", Int64.Type}, {"Data.Column7", Int64.Type}, {"Data.Column8", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Data.Column6] = null 
then [Data.Column7] else [Data.Column6]),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each if [Data.Column6] = null 
then [Data.Column8] else [Data.Column7]),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Custom.2", each if [Data.Column6] = null 
then null else [Data.Column8]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom2",{"Data.Column6", "Data.Column7", "Data.Column8"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", "Data.Column6"}, {"Custom.1", "Data.Column7"}, {"Custom.2", "Data.Column8"}})
in
    #"Renamed Columns"

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @Einomi ,

 

Suppose we have:

vcgaomsft_1-1672812218949.png

You may consider creating three new conditional columns. like this:

= if [Data.Column6] = null then [Data.Column7] else [Data.Column6]
= if [Data.Column6] = null then [Data.Column8] else [Data.Column7]
= if [Data.Column6] = null then null else [Data.Column8]

Then remove and rename the columns.

vcgaomsft_2-1672812329970.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTICYmOlWJ1oJQQnFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data.Column6 = _t, Data.Column7 = _t, Data.Column8 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Data.Column6", Int64.Type}, {"Data.Column7", Int64.Type}, {"Data.Column8", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Data.Column6] = null 
then [Data.Column7] else [Data.Column6]),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each if [Data.Column6] = null 
then [Data.Column8] else [Data.Column7]),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Custom.2", each if [Data.Column6] = null 
then null else [Data.Column8]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom2",{"Data.Column6", "Data.Column7", "Data.Column8"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", "Data.Column6"}, {"Custom.1", "Data.Column7"}, {"Custom.2", "Data.Column8"}})
in
    #"Renamed Columns"

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Thanks Gao 🙂 

@Anonymousit works good. I had to shift 6 or 7 columns but the logic works 🙂 

Einomi
Helper V
Helper V

any help 🙂

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors