Edit: Unfortunately this method isn’t working any more for files with the latest Power BI file formats (including the enhanced metadata format).
If you want to audit or analyse the M-code of multiple Power BI pbix-files at once, you start with either:
- a from-folder query where you filter all files of interest or
- a table with the full file-path-specification of the files to be analysed in “Column1”.
Then you add a column where you call the function that extracts the M-code:
Function to extract the M-code
https://gist.github.com/dbb3cd22d0825cb7d0d8f95d1ac35a31
This code is a variation of Igors function which retrieves the code from an opened pbix-file. So now you can apply it to closed pbix-files as well.
For method 1 you call it like so (as it takes the full string for the file-path as its parameter):



