LowCodeStacks™
Sign in

Power Apps user-defined functions: syntax, limits and when to use

Named formulas with parameters: how to write user-defined functions in canvas apps, behaviour functions that return Void, the settings switch, limits and status.

Power AppsFix a problem9 min read

Checked against Microsoft Learn · 12 sourcesPosted by the Maker DeskHow we write guides

Power Apps user-defined functions are named formulas with parameters. You write one once in the app's Formulas property, as Name(Param: Type): ReturnType = formula;, and call it from any control the way you call If or Filter. Microsoft announced them as generally available in September 2025; the user-defined types that let them take and return records and tables followed in May 2026.

Note

Checked against Microsoft Learn on 21 October 2026, and against the Microsoft Power Platform blog.

Which tool to use for logic you want to reuse in a canvas app. First question: is it needed in more than one app, or does it come with controls? If yes, build a component and keep it in a component library; it can expose output function properties and action properties. If no: does it take inputs? If no, use a named formula, written Name = formula, which recalculates on its own and can't have side effects. If yes: does it change state, for example with Set, Collect or Notify? If yes, write a behaviour user-defined function with its body in curly braces, returning Void if nothing comes back. If no, write a user-defined function: Name, typed parameters, a return type, then the formula. For records or tables as inputs, define a type first with := and the Type function. Functions live in App.Formulas, beside named formulas, and every parameter and the result need a type.
Three questions decide between a component, a named formula and the two kinds of function.

The syntax

User-defined functions live in the same place as named formulas. In Power Apps Studio, select App at the top of the Tree view, then pick Formulas in the property list to the left of the formula bar. Each definition ends with a semicolon:

powerfx
// App.Formulas
VatInclusive( Net: Number, Rate: Number ): Number = Round( Net * (1 + Rate), 2 );

Initials( FullName: Text ): Text = Upper( Concat( Split( FullName, " " ), Left( Value, 1 ) ) );

Then call them anywhere, for example in a label's Text:

powerfx
Text( VatInclusive( ThisItem.NetPrice, 0.2 ), "#,##0.00" ) & " incl. VAT"

The parts of a definition:

PartRequiredWhat goes there
Function nameYesThe name you call it by
ParametersNoEach written Name: Type. A function can have none
Parameter typesWith each parameterA built-in data type such as Text, Number, Date or Boolean, a data source name, or a type you define with Type
Return typeYesThe type of the value it gives back, or Void for a behaviour function that returns nothing
FormulaYesThe calculation, using the parameters by name

Every parameter and the return value must have a type. That's the main thing that separates a function from a named formula, whose type Power Apps works out for you.

Records and tables need a type first

To pass in or return a record or a table, define a user-defined type in Formulas with := and the Type function. RecordOf pulls the record type out of a table type.

powerfx
// App.Formulas
OrderLine := Type( { Net: Number, Rate: Number } );
OrderLines := Type( [ OrderLine ] );

LineTotal( Line: OrderLine ): Number = Round( Line.Net * (1 + Line.Rate), 2 );

// LineTotal( { Net: 100, Rate: 0.2 } ) returns 120
// LineTotal( { Net: 100, Rate: 0.2, Customer: "A" } ) is an error: Customer isn't in OrderLine

The second call fails on purpose. Records passed to a function are matched more strictly than elsewhere in Power Fx: the record can't carry fields that the type doesn't define. Build the record you pass, with only the fields the type expects.

The Type function doesn't support every data type. Learn lists Currency, Image, Media and Record reference as unsupported, and Void, which only ever appears as a return type.

Behaviour functions

Named formulas, and functions written as above, can't have side effects: no Set, Collect, Patch or Notify. When a function genuinely has to change something, wrap its body in curly braces, separate the steps with semicolons, and use Void as the return type if it gives nothing back:

powerfx
// App.Formulas
LogVisit( ScreenName: Text ): Void = {
    Collect( VisitLog, { Screen: ScreenName, At: Now() } );
    Notify( $"Opened {ScreenName}", NotificationType.Information )
};

Call it from a behaviour property, such as a screen's OnVisible: LogVisit( "Orders" ).

Microsoft's advice is to avoid changing state where you can, and let formulas recalculate on their own. Keep behaviour functions for real actions, such as saving, logging or notifying.

Warning

A behaviour function doesn't stop at the first error. As with any Power Fx formula, the steps after a failed one still run unless you guard them, with If around the risky steps or with IfError. A Void function can still return an error if something goes wrong.

Turning them on, and their status

FeatureStatus (October 2026)Where it's switched on
User-defined functions, including behaviour functionsGenerally available, announced 2 September 2025Part of the New analysis engine setting: Settings > Updates > New. On by default for new apps
User-defined types (Type, RecordOf in Formulas)Generally available, announced 13 May 2026Settings > Updates > New > User-Defined types. On by default for new apps from Power Apps Studio version 3.26044

They first appeared as an experimental feature in Power Apps Studio 3.24013, rolled out worldwide in February 2024. The separate preview switch was removed in version 2508.3. Microsoft folded them into the New analysis engine switch because they depend on it. Features under New are generally available and fully supported, and are normally on for new apps. In an older app, check that tab and turn the switch on yourself.

Limits to know

  • No recursion. A function can't call itself, yet.
  • Strict record matching. A record argument with an extra field is an error (see records and tables).
  • Types are mandatory. Every parameter and the result need one, and some data types can't be described with Type.
  • No side effects without braces. A plain function doesn't support Set, Notify and other behaviour functions; use the behaviour form.
  • Copilot doesn't recognise them. Learn lists user-defined functions as a limit of the formula bar's Copilot, both when it explains a formula and when it writes one from a comment. Copilot can't generate named formulas or functions for you either.
  • One app at a time. Learn documents user-defined functions only in an app's Formulas property, and describes no way to share them between apps.

Function, named formula or component?

You need...UseBecause
A value worked out from other things, with no inputs: the signed-in user's email, today's open tasksA named formula, Name = formula;It recalculates when its inputs change, and nothing can overwrite it
The same calculation in several places with different inputsA user-defined functionOne definition with typed inputs, instead of copies
The same action in several places: log, save, notifyA behaviour function returning VoidOnly the curly-brace form can change state
Logic or UI in more than one appA component kept in a component libraryApps keep a link to the library and are told about updates

A component can carry logic as well as controls. With Enhanced component properties turned on (Settings > Updates > New), a component can expose an output Function property that the app calls like a function, and an Action property that can change state. Function properties can't read variables or the component's own controls, so everything they need comes in as arguments.

Microsoft's pages don't agree on that feature's status: the component overview still calls it experimental, the component properties page lists it on the New tab and on by default for new apps, and the May 2026 announcement says it's generally available.

For how named formulas, functions and a component library fit together in one app, read named formulas and components. For choosing between a named formula, a variable and a collection, see Power Apps variables.

Do

  • Write a function the second time you paste the same formula, not the tenth.
  • Keep most functions free of side effects, and name behaviour functions after what they do.
  • Define a type once and reuse it in every function that takes the same record.

Don't

  • Don't pass a record from a data source straight into a function typed with fewer fields; build the record it expects.
  • Don't write a function that calls itself.
  • Don't rely on the formula bar's Copilot to explain or write formulas that use your functions.

User-defined functions also come up in interviews; question 11 of our Power Apps interview questions covers what to say.

Sources

Did this fix it?

Comments

No comments yet. Share what worked for you.

Sign in to comment. Comments show under a display name you choose, never your email.