Bulk-extract Power Query M-code from multiple Excel files at once

Some time ago I published a function that extracts all M-code from Power BI (.pbix)-files. Today I publish the pendant to Bulk-extract Power Query M-code from multiple Excel-files at once. The code contains many elements from the before mentioned, so please refer to that article for reference.

How to use

The function below has just one parameter where you either fill in a full filename (incl. path) of an Excel file, or a folder path where multiple files reside. The function will automatically detect the right modus and spit out the M-code.

If you want to analyse code from multiple Excel-files that don’t sit in one folder, you just create a table with a column that hold the full filenames (one in each row). Then create a new column that where you call the function that references the first column (this blogpost shows how to do it ).

You don’t have to edit or unzip the files in advance, this function will do all of that automagically.

The function code

This function is particularly useful if you want to compare code or audit your Excel-files.

Enjoy and stay queryious 😉

Comments (2) Write a comment

  1. Do you know if there is a way to do this but for all queries contained within the same workbook? For example, if you use #sections[Section1] to get the queries in the file you are in, and then to extract the M code for those queries without referencing an external file?

    Thanks!

    Reply

    • Yes, just check all queries in the query pane -> right-click mouse – copy -> paste into a text editor or your choices and you’ll get the full query-code of all your queries.

      Reply

Leave a Reply

Die Datenschutzbestimmungen finden Sie hier: / Please find the privacy policy here: https://wp.me/P6lgsG-Rz