Forum Discussion

Bridgett_B's avatar
Bridgett_B
Copper Contributor
Feb 29, 2024
Solved

Power Query import using relative path of PDF file error

Hello,

I have a query that currently imports a pdf file based on a specific file name and location.  I'm trying to make the file name and location relative but keep getting an error.  I'm using Excel365.

 

This is the Source line from the hard coded pdf import:

let
Source = Pdf.Tables(File.Contents("C:\Users\User26\Documents\Projects\IG Receivable - Schools\PCR's- Adobe Extension.pdf"), [Implementation="1.3"]),

 

When I change the code in the advanced editor to the following in order to make it relative I get an stating "DataFormat.Error: External table is not in the expected format"

 

let
FolderPath = Excel.CurrentWorkbook(){[Name="FolderPath"]}[Content]{0}[Column1],
PCRFileName = Excel.CurrentWorkbook(){[Name="PCRFileName"]}[Content]{0}[Column1],
Source = Excel.Workbook(File.Contents(FolderPath & PCRFileName), null, true),
PCRs = Source(Pdf.Tables(File.Contents((FolderPath & PCRFileName),[Implementation="1.3"])))
in
PCRs

 

I suspect the issue is with the PCRs = Source line of the code but haven't been able to figure out what.  Any suggestions?

 

Thank you

Bridgett

  • Bridgett_B 

    The first three lines of M-code should look like this:

    FolderPath = Excel.CurrentWorkbook(){[Name="FolderPath"]}[Content]{0}[Column1],
    PCRFileName = Excel.CurrentWorkbook(){[Name="PCRFileName"]}[Content]{0}[Column1],
    Source = Pdf.Tables(File.Contents(FolderPath & PCRFileName), [Implementation="1.3"]),

    Now you can navigate to the table(s) you want to extract from the PDF.

2 Replies

  • Riny_van_Eekelen's avatar
    Riny_van_Eekelen
    Platinum Contributor

    Bridgett_B 

    The first three lines of M-code should look like this:

    FolderPath = Excel.CurrentWorkbook(){[Name="FolderPath"]}[Content]{0}[Column1],
    PCRFileName = Excel.CurrentWorkbook(){[Name="PCRFileName"]}[Content]{0}[Column1],
    Source = Pdf.Tables(File.Contents(FolderPath & PCRFileName), [Implementation="1.3"]),

    Now you can navigate to the table(s) you want to extract from the PDF.

Resources