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 (5) 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?



    • 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.


  2. Hello.
    I apologize for my English, which is not very good.
    Is it possible to extract zip files with password in power query? For example, by setting the zip file password for unpacking directly in the function?

    Thank you for your help.


  3. Absolutely fantastic code. Have been searching for something like this for a long time. Thank you very much ­čÖé


Leave a Reply

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