Guidelines to Improve Canvas Applications

PowerFx is a low-code programming language used in Microsoft Power Apps to build canvas applications. PowerFx formulas can become complex, making the application slow, affecting its performance. Here are some changes you can make in PowerFx canvas formulas to improve performance.

  1. Use IfError() function instead of catching errors: PowerFx provides Try() and Error() functions to catch errors in formulas. However, using these functions can slow down formula evaluation. Instead, use the IfError() function to return a default value when an error occurs. For example, =IfError(10/0, “Division by zero”)
  2. Use Filter() function instead of Search() function: The Search() function can be slow when working with large datasets. Instead, use the Filter() function, which is delegated, meaning the filtering is done on the data source, resulting in faster performance. For example, =Filter(MyDataSource, MyField=”Value”)
  3. Use Collect() function instead of Patch() function: The Patch() function can be slow when used to update a large number of records. Instead, use the Collect() function to collect data into a local collection, and then use the ClearCollect() function to send the updated data back to the data source in batches. For example, =ClearCollect(MyCollection, MyDataSource); Collect(MyCollection, {ID: 1, Name: “Value”})
  4. Use Variables to store intermediate results: Storing intermediate results in variables can help simplify complex formulas and reduce formula evaluation time. For example, varMaxValue = Max(MyDataSource, MyField); varMinValue = Min(MyDataSource, MyField); Sum(MyDataSource, If(MyField=varMaxValue || MyField=varMinValue, MyField, 0))
  5. Use ForAll() function instead of ForEach() function: The ForEach() function processes one item at a time, making it slow when working with large datasets. Instead, use the ForAll() function, which can process multiple items simultaneously, resulting in faster performance. For example, =ForAll(MyDataSource, MyField * 2)
  6. Use Delegation: Delegation is a technique that offloads data processing to the data source, which can significantly improve performance. When a PowerFx formula filters, sorts or searches data, it can delegate the operation to the data source, reducing the amount of data loaded into the application. For example, =Filter(MyDataSource, MyField > 10)
  7. Use appropriate control properties: Use appropriate control properties to reduce the amount of data loaded into a control. For example, use the Items property to load a limited set of data into a gallery or list, and use the OnVisible property to load additional data when a control is displayed. For example, =Gallery(Items: FirstN(MyDataSource, 50))
  8. App.Formulas is a feature in Microsoft Power Apps that allows developers to create and use custom functions in canvas applications. With App.Formulas, developers can define their own PowerFx functions that can be used in any formula within the application. This can help simplify complex formulas, improve performance, and enhance the user experience.

In summary, improving the performance of a canvas application requires optimizing PowerFx formulas to reduce complexity, and using functions that are delegated to the data source for faster processing. Additionally, it is important to use appropriate control properties to reduce the amount of data loaded into a control, and to use variables to store intermediate results. With these changes, the performance of a canvas application can be improved, resulting in a better user experience.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a website or blog at WordPress.com

%d bloggers like this: