“Just because you could doesn’t mean you should”… So I’m asking the Power Query and M fans & experts here if we “should” pipe M:
Background: With M you can nest your expressions like in Excel to group commands that belong together. But this has some disadvantages like:
- the execution order of the functions doesn’t match the reading order
- the function name and the arguments are torn apart
- if you write an additional function around the existing expression which then fails, it is very laborious to manually delete all the code to go back to the previous state (especially, if you have trailing function arguments)
- if you later recon that you need an intermediate step of the nested expression and need to split up the statement, the same problems occur
So instead of this code:
we could write it like so:
This code works in M if you have a record (“M”) in your queries that contains Kim Burgess’ cool code and an additional record (“M”) that he has kindly helped me with:
All that still folds!
Honestly, it doesn’t look pretty in my eyes (yet), but it works and eliminates the disadvantages mentioned above. With some help of Expression.Evaluate, we could further clean it up to match the magrittr-style for example, but I’ve been warned to use this function, so not sure what to prefer at the end.
Please let me know your thoughts & stay queryious 😉
File to download: ShouldWePipeM.zip