One function
Imagine a file (here named add_nums.M
) with the following (simple because of demonstration purposes) function:
(a, b) => a + b
This function can then be executed with the following expression:
let
add_nums = Expression.Evaluate(Text.FromBinary(File.Contents("C:\Users\rene\PowerQuery\GlobalFunctions\add_nums.M")))
in
add_nums(9, 33)
Multiple function
Multiple functions can be stored in a file using a
record structure:
[
mult = (a,b) => a * b,
add = (a,b) => a + b,
sub = (a,b) => a - b,
div = (a,b) => a / b
]
A function can then be selected from the record like so:
let
funcs = Expression.Evaluate(Text.FromBinary(File.Contents("C:\Users\rene\PowerQuery\GlobalFunctions\funcs.M")))
in
funcs[sub](61,19