Forum Discussion
Losing a column when importing PDF
I'm working with a folder where I have some PDFs, all with the same structure.
I've developed a function to just upload the files to that folder and automatically apply all transformations and operations to the table. However, I've noticed that power query sometimes recognize the PDF as 2 tables and sometimes as 3 tables.
My main problem is that when it recognizes 3 tables, it skips one column of data that I need.
Does this problem have any solution?
Thank you
10 Replies
- AnonymousNot applicable
To prevent this, I always add a ColumnCount column that tells me the number of columns in each pdf table. Then I sort by greatest to least. This way, your sample file has the maximum number of columns, and when you expand them, you will no longer lose any data!
--Nate
- diego_martineznFrequent Visitor
Hi Anonymous , first of all, thank u for answering.
Here it's what I've done based on your answer. I add a personalized column where I count the number of columns of each table and sort them, so what I get is three tables sorted as follows: {21columns, 11 columns, 9columns}.
Then I click on the expand button, and as you said the whole new table has 21 columns but it fills with "nulls" where my missing data should be.
I think this procedure is what you meant right? Maybe I'm skipping some steps or don't do it correctly. Let me know 🙂
- edhansCommunity Champion
I'm not sure about the PDF connector, but check out your M code in the Advanced editor. The first line for a CSV import though might look like this:
= Csv.Document(#"C:\Users\FileList txt",[Delimiter=":", Columns=2, Encoding=1252, QuoteStyle=QuoteStyle.None])It doesn't matter if that file gets a 3rd column added, it will always only read the first two. I remove that.
= Csv.Document(#"C:\Users\FileList txt",[Delimiter=":", Encoding=1252, QuoteStyle=QuoteStyle.None])See if your PDF connection has that same setting.
- diego_martineznFrequent Visitor
Hi edhans , thanks for answering :).
For the PDF the code generated automatically is this:
= Pdf.Tables(File.Contents("C:\whatever direction i have the file"), [Implementation="1.3"])Any thoughts on how to solve the issue?
- edhansCommunity Champion
Are all columns coming in, but your M code isn't handleing a 2 or 3 column table depending on the file? If so, check out this blog post. Removing/Selecting Columns - Pitfall #5 in #PowerBI and #PowerQuery - DataChant - particularly the MissingField.Ignore discussion.
- v-yanjiang-msftCommunity Support
Hi diego_martinezn ,
Could you please share your PDF without any sensitive data here? It will helpful to solve your problem.
Best Regards,
Community Support Team _ kalyj