Search code examples
powerquery

How can I reference a .pqm file from a .pq file in Power Query SDK?


I am working through Microsoft's TripPin Custom Connector walkthrough tutorial. In Part 7 there is a section on refactoring some code into separate .pqm files and referencing these from the .pq file.

The code in the sample uses an M Query function Extension.Contents() to get the contents of the .pqm file(s). However in my code VS Code underlines this as a compilation error with the message "Cannot find the name 'Extension.Contents'.powerquery(Error.UnknownIdentifier)".

Even when I download the full code sample from the related Microsoft GitHub project I get the same issue.

I wonder if this is because the version of the VS Code extensions I'm using is too recent and the tutorials and sample code have not been updated, I have tried some older versions without success.

How do I resolve this?

I am currently using the latest extensions:


Solution

  • I think I figured it out. I noticed that if I open just the TripPin part 7 sample code folder in VS Code (rather than the top level "DataConnectors" folder from the GitHub repo) then the compilation error goes away.

    Then by a "spot the difference" process I noticed that there was a difference in the settings.json file in that folder vs the code I was working on. The third line of the settings.json file (below) was missing from my code, once I added this everything worked fine.

    {
      "powerquery.sdk.defaultQueryFile": "${workspaceFolder}\\${workspaceFolderBasename}.query.pq",
      "powerquery.sdk.defaultExtension": "${workspaceFolder}\\bin\\AnyCPU\\Debug\\${workspaceFolderBasename}.mez",
      "powerquery.general.mode": "SDK",
    }