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.
Admittedly, Microsoft languages have rarely been known for encouraging open-source collaboration, and the Power Query community is currently small. But will that mean we cannot assemble a powerful code library like those of the JavaScript community?
- 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
cmd
in the address bar) and run commandgit clone https://github.com/KiaraGrouwstra/pquery.git
. - copy
LoadPath.example.pq
asLoadPath.pq
and replace its entire content with the path where you put the query files; e.g."D:\pquery\"
. - manually import the
Load.pq
andLoadPath.pq
functions into your workbook, keeping their names asLoad
andLoadPath
. - 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 atYOUR_PATH\Text.Between.pq
.
- 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.
Power-BI-Desktop-Query-Extensions
- newer library including in-app function documentationPowerQueryExtensions
- library using the recentDataConnectors
API to expose the functions from this and the above librarym-tools
- functional programming helpersPowerQueryFunctional
-DataConnectors
port of the above libraryatom-language-m
- Atom support for MLibPQ
- 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!):