This is a collection of functions written in the M language for use in Microsoft Excel's Power Query plugin.
Rather than manually adding the functions to different Excel workbooks, users can instead leave their files in any directory, and either batch import them into your workbook using Excel 2016 VBA (see my sample workbook here), or by dynamically loading them into Power Query using something like the
Load() function (see
Load.pq). To use Load() you'll need to add it to every applicable workbook though. You can hard-code in the path to the folder where you put the functions from this repository, or set it in the specified cell in the above-mentioned sample workbook for use in that.
To manually add the Load query, click 'From Other Sources' in the Power Query ribbon tab, select 'Blank Query' (bottom option), open the Advanced Editor in the View tab, and paste in the below snippet (after adjusting file path). Click Done, name the query 'Load', and click 'Apply & Close' in the Home tab.
If you have your M queries in files, you may well prefer to edit them from a text editor like Notepad++. With Matt Mason's language file for this you will get nice color coding too!
The main point here is that by separating universally useful functions from an individual workbook, you will feel encouraged to use more modular code, solving each common sub-problem only once, rather than remaining stuck in 'vanilla' M and resolving the same problems repeatedly.
Moreover, coding this way will also further facilitate sharing code with other Power Query users, allowing for a more collaborative environment.
to use M code in workbooks without having to import every query/function:
- get and unzip this repo, or in case you'd like to contribute back, open a command prompt in your desired location (in Windows Explorer type
cmdin the address bar) and run command
git clone https://github.com/tycho01/pquery.git.
LoadPath.pqand replace its entire content with the path where you put the query files; e.g.
- manually import the
LoadPath.pqfunctions into your workbook, keeping their names as
- now use the Load function to load queries from the folder you specified. i.e. if you write
Text_Between = Load("Text.Between"),, it's going to give you the function located at
to allow sharing your workbook:
- use my Power Query workbook (requires Excel 2016) to batch import the desired queries into your workbook. Chris Webb also posted the used VBA code, and did an introductory blog post about it.
Related Projects (feel free to add!)
Power-BI-Desktop-Query-Extensions- newer library including in-app function documentation
PowerQueryExtensions- library using the recent
DataConnectorsAPI to expose the functions from this and the above library
m-tools- functional programming helpers
DataConnectorsport of the above library
atom-language-m- Atom support for M
LibPQ- a collection of reusable modules for Power Query M Language
For more Power Query related repos check out some of the following users (sorted alphabetically, feel free to add!):