You shouldn’t do it …
Generally it’s a very bad idea to execute commands in Power Query that write out data to a source, as these commands might be executed multiple times (https://blog.crossjoin.co.uk/2018/10/07/power-query-write-data/)
… unless … maybe ?
However, as with most good rules, there are exceptions. I leave it to you to decide whether my use case here is a valid candidate for it. It doesn’t execute the code twice, because I execute the query only from the query editor and none of the other queries is referencing its results. But please see for yourself – Writing data to GitHub using just Power Query:
In the video I show how I enrich my M-functions with metadata before loading it directly with Power Query into a new Gist on GitHub. Then I trigger an automatic update of my Function-library (M-extension). Therefore I have to switch to Power BI, because it currently not possible to run R- or Python-Scripts in Excel (which writes the .mez-file for me into the destination-folder).
Trading code for votes
The code I’m sharing today is the one that exports the M-code to GitHub. I’m going to share the full solution, as soon as the following features are implemented in Excel (like they are in Power Query for Power BI currently):
You can help this by upvoting the ideas of the links above. Actually, my guess is that we need around 1000 votes for these features to be considered. So please share this article with your colleagues and friends to make this happen.
You need an access token from GitHub for Power Query to pull your data from your repos and gists: https://github.com/settings/tokens
Why I am so passionate about this?
In my eyes, these features hold the key to make the Power Tools in Excel really easy and efficient to use:
- Difficult, cumbersome or complex tasks can be packaged into functions. Just fill in the function parameters and you’re done. You don’t have to learn the M-language but just how to use the functions from the custom libraries. (examples: https://www.thebiccountant.com/2017/06/19/unpivot-by-number-of-columns-and-rows-in-powerbi-and-powerquery-in-excel/, https://www.thebiccountant.com/2017/05/23/goal-seeking-and-xirr-in-powerbi-and-powerquery/ )
- Prevention of slow running queries: Many of the solutions that Power Query beginners learn are optimized to be handled by the UI only and not for performance. With custom functions, also beginners can create solutions that handle large amounts of data that won’t bring their computers to a standstill. (examples: https://www.thebiccountant.com/2018/07/12/fast-and-easy-way-to-reference-previous-or-next-rows-in-power-query-or-power-bi/, https://www.thebiccountant.com/2018/09/30/memory-efficient-clustered-running-total-in-power-bi/)
Thanks for your votes, enjoy & stay queryious 😉