Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
Dear all,
In terms of structuring my power query analysis I was wondering is it possible to put all your functions in a single query and then call them as required. At the moment each of my functions is its own query. Is it possible to consolidate these all together. In a similar way one as you may have a file/module in another language that contains all related functions.
For example I would like to a have a single query/file that contains the functions
/* my functions
add = (x, y) =>
let
return = x + y
in
return
subtract = (x, y) =>
let
return = x - y
in
return
*/ end of my functions
/* Then a new query
let
myTable = someTableOfData
_1 = Table.SelectColumns(myTable, {"numberColumn"}),
_2 = Table.AddColumn(_1, "numberAdd1", each add([numberColumn],1))
in
_2
Solved! Go to Solution.
No, it is not possible.
You can combine functions in 1 query, but only call them from within the same query.
The way to structure your queries is to group them: in the edit queries pane you can select your functions, rightclick and choose Move to Group and move your functions to an existing group or to a new group.
Actually, you could return your functions as properties of a record. As far as I know, this would be the closest you would get to modules.
Module = [add = (x,y) => x+y, multiply = (x,y)=>x*y]
Calling a function:
= Module[multiply](12,14)
No, it is not possible.
You can combine functions in 1 query, but only call them from within the same query.
The way to structure your queries is to group them: in the edit queries pane you can select your functions, rightclick and choose Move to Group and move your functions to an existing group or to a new group.
Thanks for that. That is what I suspected. I have grouped my functions as you suggest, but was thinking it might get messy if I start to make use of user created functions to any extent.
I was playing around with the sections command in M, but I think that while it exists in the Language Specification it might not have been implemented.
Actually, you could return your functions as properties of a record. As far as I know, this would be the closest you would get to modules.
Module = [add = (x,y) => x+y, multiply = (x,y)=>x*y]
Calling a function:
= Module[multiply](12,14)
I have tried that out and it works great. I can have all my functions as members of a record in one query and then call them from wherever I need to.
Thanks!
That is a really great idea! I think I will do that where I have functions that make sense to group together.
During my investigations I came to the similar conclusion that the Power Query UI's (in Excel and Power BI) are a kind of layers on top of the M language, and that these layers don't provide access to the entire core M language.
Note: that is my own conclusion, it may not be entirely true, but apparently we have similar thoughts.
User | Count |
---|---|
141 | |
113 | |
104 | |
77 | |
64 |
User | Count |
---|---|
135 | |
123 | |
101 | |
71 | |
61 |