PowerQuery question: what's the best way to fix misaligned columns?

ExcelOnTheClock

New Member
Joined
Dec 1, 2022
Messages
19
Office Version
  1. 365
Platform
  1. Windows
Hello,

I'm trying to import several PDF files into PowerQuery. There's a section in the PDF that looks like this:
1670551356889.png


However, when I import the PDFs, the columns keep getting misaligned, looking like this jumbled mess:
1670551387710.png


What's the best way to fix it?

Thanks in advance for the help!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Also Amy's row has a mistake. There's four 1s in her row, I shouldn't have included those. It should just be 2 items per person.
 
Upvote 0
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    tbl = Table.AddColumn(Source, "Custom", each List.RemoveNulls(Record.ToList(_))),
    Result = Table.FromRows(tbl[Custom], {"Person","Item1", "Item2"})
in
    Result

Book1
ABCDEFGHIJKL
1PersonItem1Item2Item3Item4Item5Item6PersonItem1Item2
2A11A11
3B11B11
4C11C11
5D11D11
6E11E11
7F11F11
8G11G11
9
Sheet2
 
Upvote 0
Solution
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    tbl = Table.AddColumn(Source, "Custom", each List.RemoveNulls(Record.ToList(_))),
    Result = Table.FromRows(tbl[Custom], {"Person","Item1", "Item2"})
in
    Result

Book1
ABCDEFGHIJKL
1PersonItem1Item2Item3Item4Item5Item6PersonItem1Item2
2A11A11
3B11B11
4C11C11
5D11D11
6E11E11
7F11F11
8G11G11
9
Sheet2
Thanks! The easiest way to do this is to write this M code? I'm VERY new to PowerQuery, was hoping there was a less custom way. If not, all good! This will get the job done!
 
Upvote 0
Hello,

I'm trying to import several PDF files into PowerQuery. There's a section in the PDF that looks like this:
View attachment 80488

However, when I import the PDFs, the columns keep getting misaligned, looking like this jumbled mess:
View attachment 80489

What's the best way to fix it?

Thanks in advance for the help!
If you want a UI solution... Do as you do, finally select the first column and select Unpivot other columns from the ribbon.
Should do the trick.
 
Upvote 0
Hi ExcelOnTheClock,

I saw this as an opportunity to learn "import from pdf", as I never needed it before. So I tried to simulate the issue.
Assuming all PD files are alike, I did put them together in a single folder.
PDFs look like below, a simple mock-up.
1670750387133.png


Loading from folder and applying the default transformation function it creates, the result ends up nicely.
Power Query:
let
    Source = (Parameter1) => let
        Source = Pdf.Tables(Parameter1, [Implementation="1.3"]),
        Table001 = Source{[Id="Table001"]}[Data],
        #"Promoted Headers" = Table.PromoteHeaders(Table001, [PromoteAllScalars=true])
    in
        #"Promoted Headers"
in
    Source

Power Query:
let
    Source = Folder.Files("G:\Uploads\PDF_mrXlForum"),
    #"Filtered Hidden Files1" = Table.SelectRows(Source, each [Attributes]?[Hidden]? <> true),
    #"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File", each #"Transform File"([Content])),
    #"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
    #"Removed Other Columns1" = Table.SelectColumns(#"Renamed Columns1", {"Source.Name", "Transform File"}),
    #"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File", Table.ColumnNames(#"Transform File"(#"Sample File"))),
    #"Changed Type" = Table.TransformColumnTypes(#"Expanded Table Column1",{{"Source.Name", type text}, {"Person", type text}, {"Item", Int64.Type}, {"Item2", Int64.Type}})
in
    #"Changed Type"

1670750499676.png

So I now wonder what's been your way to get to the messed-up table? But maybe the above is a way to avoid custom M-code and have a UI based solution. Not my previous reply, as I misunderstood you actually want 2 columns for each row.
 
Upvote 0

Forum statistics

Threads
1,223,986
Messages
6,175,788
Members
452,670
Latest member
nogarth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top