Forum Discussion
NJamigos
3 years agoFrequent Visitor
Transform multiple sample page / query
I'm trying get data from pdf files. Its first page data is slightly different from other pages. First I filtered 1st page and did transformation in sample transformation query. After that from there ...
Sahir_Maharaj
3 years agoSuper User
Here are the general steps:
Sahir_Maharaj
3 years agoSuper User
Here is an example M code to get you started:
- Sahir_Maharaj3 years agoSuper User
let // Step 1: Get list of PDF files Source = Folder.Files("C:\Path\To\PDF\Folder"), PDFFiles = Table.SelectRows(Source, each [Extension] = ".pdf"), // Step 2: Combine PDF files into single binary column CombinePDFs = Table.AddColumn(PDFFiles, "Contents", each Binary.Combine({[Content]})), // Step 3: Extract tables from PDF files ExtractTables = Table.AddColumn(CombinePDFs, "Tables", each Pdf.Tables([Contents], [Name])), ExpandedTables = Table.ExpandTableColumn(ExtractTables, "Tables", {"Data", "Columns"}, {"Data", "Columns"}), // Step 4: Clean and reshape data as needed // ... // Combine all tables into a single table CombinedTables = Table.Combine(ExpandedTables[Data]) in CombinedTables- Sahir_Maharaj3 years agoSuper User
This code assumes that all of the PDF files in the folder have tables on their pages.
If some of the files do not have tables or have different structures, you may need to add additional logic to handle those cases.
- NJamigos3 years agoFrequent Visitor
Data is not structured as tables in pdf. In my case first page structure is little different from other pages. I did transformation to make both same but when appending to 'transform sample '.. Other pages is repeating first pdf data.
What might I have done wrong?