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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Mat42
Resolver I
Resolver I

Integrate Custom Function

So, I've inherited a PBI report that contains a custom function (helpfully named 'Function1'). It pulls data out activity data for a specific timeframe. The person who created the report used to run this function manually everytime they needed it. It creates a table named 'Invoked function'. The data from this table is exported into Excel then the table is deleted.

 

The thing is, the date range is always the same: Today and the previous 30days.

 

How do I automate this function so that it runs automatically everytime I refresh the report? Also, how do I set it so that it overwrites the previous invoked function table? Currently, running it more than once creates more tables 'Invoked function 2...3...etc'.

1 ACCEPTED SOLUTION
anilelmastasi
Solution Supplier
Solution Supplier

Hello Mat42,

 

You can automate the execution of Function1 and ensure it refreshes correctly without creating multiple "Invoked function" tables by following these steps:

 

First Step

If Function1 has date parameters, modify it to use dynamic dates instead of requiring manual input.

 

let
    StartDate = Date.AddDays(Date.From(DateTime.LocalNow()), -30),
    EndDate = Date.From(DateTime.LocalNow())
in
    Function1(StartDate, EndDate)

 

 

Second Step

Instead of manually invoking Function1, create a new table that invokes it dynamically:

  1. In Power Query Editor, click New Source → Blank Query.
  2. Rename this query to something meaningful, e.g., ActivityData.
  3. Use the following formula to invoke Function1 automatically:

 

= Function1(Date.AddDays(Date.From(DateTime.LocalNow()), -30), Date.From(DateTime.LocalNow()))
​

 

  • Click Close & Apply.

Now, every time the report refreshes, ActiviyData will update automatically.

 

Third Step

If Power BI is creating multiple "Invoked function" tables (e.g.,Invoked function 2, Invoked function 3) , it’s likely because you are manually invoking the function instead of defining a static query. Delete all existing tables from Power Query Editor and use the new ActivityData query instead.

 

Fourth Step

To automate refreshing, set up a scheduled refresh in Power BI Service after publishing the report.

 

Did I answer your question? Mark my post as a solution, this will help others!

If my response assisted you in any way, don't forget to drop me a "Kudos.

Kind Regards,

View solution in original post

3 REPLIES 3
anilelmastasi
Solution Supplier
Solution Supplier

Hello Mat42,

 

You can automate the execution of Function1 and ensure it refreshes correctly without creating multiple "Invoked function" tables by following these steps:

 

First Step

If Function1 has date parameters, modify it to use dynamic dates instead of requiring manual input.

 

let
    StartDate = Date.AddDays(Date.From(DateTime.LocalNow()), -30),
    EndDate = Date.From(DateTime.LocalNow())
in
    Function1(StartDate, EndDate)

 

 

Second Step

Instead of manually invoking Function1, create a new table that invokes it dynamically:

  1. In Power Query Editor, click New Source → Blank Query.
  2. Rename this query to something meaningful, e.g., ActivityData.
  3. Use the following formula to invoke Function1 automatically:

 

= Function1(Date.AddDays(Date.From(DateTime.LocalNow()), -30), Date.From(DateTime.LocalNow()))
​

 

  • Click Close & Apply.

Now, every time the report refreshes, ActiviyData will update automatically.

 

Third Step

If Power BI is creating multiple "Invoked function" tables (e.g.,Invoked function 2, Invoked function 3) , it’s likely because you are manually invoking the function instead of defining a static query. Delete all existing tables from Power Query Editor and use the new ActivityData query instead.

 

Fourth Step

To automate refreshing, set up a scheduled refresh in Power BI Service after publishing the report.

 

Did I answer your question? Mark my post as a solution, this will help others!

If my response assisted you in any way, don't forget to drop me a "Kudos.

Kind Regards,

You are a beautiful human @anilelmastasi. That is exactly what I need.

 

Thank you so much.

You are welcome @Mat42 ! Anytime 😊

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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