Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
NBEN66
Frequent Visitor

Dynamically import custom functions

Hello Everyone, 

 

At our company we are trying to automate customer orders that are sent in via PDF. We have hundreds of customer with different PDF templates. We decided to use Power query PDF import to solve this task, and edit each PDF to the desired format. Not the best solution but it is working. We are using an excel as front end where employees can select each instance run the query extract the data and than a macro uploads it to SAP. The problem we are facing is that we store these solutions as custom function in power query and based on instance selected the query invokes the matching solution. At the moment we have 50 custom function in the file. For some reason this makes the file basically unusable its like it trying to load each custom function at the same time even though we disabled that setting.

And our question is: is it possible to import a Custom function for example from txt with a custom function ? So in the end in the file itself there are two function one that import the correct solution and one that runs it ?

1 ACCEPTED SOLUTION
jennratten
Super User
Super User

Hello - yes, this can be done.  Here is an example:

let
    //Load M code from text file
    Source = Text.FromBinary(File.Contents("C:\PathToYourFile.txt")),
    //Evaluate the code from the file as an M expression
    EvaluatedExpression = Expression.Evaluate(Source, #shared)    
in
    EvaluatedExpression 

View solution in original post

3 REPLIES 3
jennratten
Super User
Super User

Hello - yes, this can be done.  Here is an example:

let
    //Load M code from text file
    Source = Text.FromBinary(File.Contents("C:\PathToYourFile.txt")),
    //Evaluate the code from the file as an M expression
    EvaluatedExpression = Expression.Evaluate(Source, #shared)    
in
    EvaluatedExpression 

You are a life saver, thank you! 

You're welcome!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors