Automatically create function record for Expression.Evaluate in Power BI and Power Query

Some time ago I wrote a blogpost on how to create a function library in Power BI or Power Query ( There I also presented a way to pull that function code automatically from GitHub.


In that code I used the function Expression.Evaluate to execute the imported text and create functions from it. The inbuilt functions that I’ve used in that code have to be passed as an environment record at the end of the expression. I’ve used #shared for it, as this returns a record with all native M-functions and is quick and easy to write (if environments are new to you, check out this series: ). But as it turns out, this can cause problems when publishing to the service unfortunately ( – please leave a vote if you would like to use #shared in the service as well).


To bypass these problems, you can specify each used function individually (as you can see in Tony McGoverns newest treasure here for example: ).

But depending on the length and complexity of your function, determining which functions are used and manually write down the record can become a bit laborious and spoil the fun. Therefore, I’ve created a function that does that for you autoMagically:

The formula

For the record

Pass in the query text as the first parameter and you’ll get a text string for the record:

Function record for Expression.Evaluate

For the query

And if you additionally pass in the URL for your function code as well, the full Expression.Evaluate-statement will automatically be created for you:

Full query text for Expression.Evaluate

Be aware, that the results of these functions are text that you have to copy and paste into your function code. You cannot simply reference the query, as this would repeat the problem with #shared.

Enjoy & stay queryious 😉

Comments (5) Write a comment

  1. Pingback: How to create and use an R-function-library in Power BI – The BIccountant

  2. Pingback: Using functions to create a filter in Power Query - Foster BI

  3. Pingback: Dynamically create types from text with Type.FromText in Power Query and Power BI

  4. Hello there,

    Is there a way of using the output directly and make it become a record? I am not using #shared at all. I have a list with all the names of my custom functions.

    Assuming my custom functions’ names are a, b and c. Your code helps generating the record codes [a=a,b=b,c=c] for the ease of copy-and-paste, but I want to make a actual record out of it.

    Is there a way of doing so?

    Thank you so much for your help.

    Best regards,


    • Hi David,
      no, the nature of this solution prohibits this (as it’s using shared itself and wouldn’t work in the service).
      So it’s just a helper-function that returns the string for your specific solution.


Leave a Reply

Die Datenschutzbestimmungen finden Sie hier: / Please find the privacy policy here: