Mastering UDFs and UDTs for Professional App Development

Best Practices Canvas Apps Power Apps Automation Development Documentation Power Platform Software Engineering

Making use of Named formulas (NFs) and User defined functions (UDFs) is crucial in order to maintain a modular and thus scalable approach to structure your Power Platform Canvas Apps. They really play a significant role in bringing development of Canvas Apps to a pro-dev related level by helping in encapsulating logic, reducing redundancy, and improving maintainability.

User Defined Types (UDTs) complement UDFs by allowing developers to define custom data types, which then can be used to enforce type safety and improve the structure of your data.

Announced on the Power Platform blog in January 2025, at the time of writing the features are still in preview but already available for use (and therefore expected to become generally available in the near future).

Together, UDFs and UDTs are powerful features for creating more maintainable and scalable applications. As these features continue to evolve, they will likely become essential tools for professional app developers working with Power Apps.

Note

For the sake of clarity, this article will focus on the new features of UDFs and UDTs, as Named formulas have been around for a while and are not the focus here.

User defined functions (UDFs)

User defined functions (UDFs) are not the same as Power Fx formulas. UDFs are reusable functions that enable you to write your own functions that take parameters and return values, similar to functions in programming languages. This allows you to encapsulate logic and reuse it across your app, which is essential for maintaining clean and efficient code.

You should distinguish between non-behavioral UDFs and behavioral UDFs (at least Microsoft does). The latter contain actions, so the entire function body must be written within curly braces.

Non-behavioral UDFs are used for calculations or data filtering and are defined like this:

MyNonBehavioralUDF(param1: <ParamType>, param2: <ParamType>): <ReturnValue> = <Formula>

Each parameter and the output from the user define function must be typed, which ensures type safety and helps prevent errors in your app. The return value can be a primitive type (like Number, Text, etc.) or a more complex type like a record or table (for the latter, see the section below).

Behavioral UDFs can perform actions or side effects (data manipulation, for example by using Set(...) or Navigate(...)) and are defined like this (note the curly braces):

MyBehaviouralUDF(param1: <ParamType>, param2: <ParamType>): <ReturnValue> = {
    // Do something with param1 and param2
    // ...
    // ... and then return a result or not
}

Note

Have a look at the section below for guidance on when to use UDFs and when better not to use them.

User defined types (UDTs)

User-defined types (UDTs) add another feature that increases the possibilities for boosting productivity and handling data types by introducing type safety. UDTs let you define data types or object definitions (aka records) which can be used in combination with UDFs to define function headers or return values according to specific needs.

Just define them by using the Type function (which is a new keyword in Power Apps):

MyCustomType := {
    Field1: Text,
    Field2: Number
}

By using the RecordOf function (which is also a new keyword in Power Apps), you would be able to define derived data types or object definitions (aka records) from tables that come along used data sources (for example SharePoint list data items or Dataverse tables):

MyDerivedType := Type(RecordOf(<TableName>))

Basically, UDTs improve how data is modelled and manipulated in your app and therefore provide a type-safe approach in regards to data manipulation.

Any defined UDT can be used as a parameter type or return type in UDFs. This means you can enforce a specific structure for the data being passed around in your app, which helps prevent runtime errors and improves code readability.

How to make UDFs and UDTs available

All these guys need to be defined in the Formulas property of the app itself and are then globally accessible within the whole app. These components are recognized as the new “building blocks” of modern and robust Canvas Apps.

Note

At the time writing, UDFs and UDTs aren’t generally available. You have to turn the feature on in the Power app’s settings. Beyond that, you may encounter „special behavior“ while using them in your app (see below).

When to use UDFs and when not

Mapping, filtering and mutating collections, calculating values, and functions for logging and debugging seem to work like a charm.

User-defined functions are primarily for calculations and data manipulation within the app itself, but not (yet) for directly initiating external processes like calling flows within a process.

Warning

💣 pay attention! Any flow that is called from a UDF will return a null value when running the app in „play“ mode (standalone) — while it is working when running the in Preview mode within Power Apps Studio. ☠️

#BishopTells