Create Custom Power Fx Functions with Enhanced Component Properties
A step-by-step guide to building a reusable PMT function using enhanced component properties, so you never have to write the same formula twice.
The DRY (Don’t Repeat Yourself) principle is one of the most powerful habits a developer can adopt. In Power Apps, it has historically been challenging to avoid copying complex formulas across multiple screens and apps. With the introduction of enhanced component properties, you can now build custom functions—blocks of Power Fx logic that you write once and invoke anywhere. This guide walks you through creating a practical custom function that calculates a loan’s monthly payment (PMT). The same pattern works for any repetitive calculation you want to centralize.
Original Example Scenario
Imagine your company manages several loan programs—small business loans, equipment financing, employee advances—and each app needs to compute the same monthly payment formula. Rather than rewriting (rate * principal) / (1 - (1 + rate)^-term) in every screen, you create a PMT custom function inside a reusable component. The component can be added to any app, and its function accepts the annual rate, term in months, and loan amount, returning the payment instantly.
Step 1: Enable the Experimental Feature
Custom functions rely on Enhanced component properties, an experimental feature. To turn it on:
- Open your app in Power Apps Studio.
- Go to Settings → Advanced settings.
- Set Enhanced component properties to On.
Enhanced component properties are still in preview. Test thoroughly before rolling into production apps.
Step 2: Create a New Component
From the left navigation pane, switch to the Components tab and click New component. Name it something meaningful, like FinancialFunctions.
Step 3: Add a Custom Function Property
With the component selected, click New custom property in the right pane. Configure it as follows:
- Property name:
PMT - Property type: Output
- Data type: Number
Click Create. Now you need to define the parameters that callers will supply.
In the custom property editor that opens, click + New parameter for each input:
| Parameter | Data type | Required |
|---|---|---|
AnnualRate | Number | Yes |
TermMonths | Number | Yes |
LoanAmount | Number | Yes |
After creating all three, click Save.
Step 4: Write the PMT Function Logic
With the PMT property still highlighted in the component properties list, enter the following code in the formula bar. It handles a zero‑interest rate gracefully and uses the standard loan payment formula otherwise.
If(
AnnualRate = 0,
LoanAmount / TermMonths,
With(
{
monthlyRate: AnnualRate / 12
},
(monthlyRate * LoanAmount) / (1 - Power(1 + monthlyRate, -TermMonths))
)
)The With statement keeps the formula readable and avoids repeating AnnualRate / 12.
Step 5: Use the Custom Function on a Screen
Go to any screen in your app and insert the FinancialFunctions component from Insert → Components. Rename it to something short, like cmp_Fin.
Add a Label control and set its Text property to:
cmp_Fin.PMT(0.05, 36, 15000)
Assuming a 5% annual rate, 36 months, and a $15,000 loan, the label will display approximately $449.26. You can replace the hard‑coded values with inputs from text boxes or sliders to make a fully interactive loan calculator.
Step 6: Add an Optional Parameter
To make the function more versatile, add an optional FutureValue parameter:
- In the
PMTproperty editor, click + New parameter. - Set Data type to Number, leave Required unchecked.
- Under Default value, enter
0.
Update the formula to incorporate future value (a standard extension of the PMT formula):
If(
AnnualRate = 0,
(LoanAmount - FutureValue) / TermMonths,
With(
{
monthlyRate: AnnualRate / 12,
denom: 1 - Power(1 + monthlyRate, -TermMonths)
},
(monthlyRate * (LoanAmount - FutureValue / Power(1 + monthlyRate, TermMonths))) / denom + FutureValue * monthlyRate / Power(1 + monthlyRate, TermMonths)
)
)Now callers can optionally provide the amount they expect to owe at the end of the term, e.g., cmp_Fin.PMT(0.05, 36, 15000, 3000).
Performance and Delegation Considerations
- Custom functions run entirely on the client. They do not delegate to the server, so avoid using them inside large data source filters unless the dataset is small.
- Calculations are instantaneous for individual function calls. Looping over thousands of records to call a custom function may cause noticeable delays.
- For operations that need to process millions of rows, prefer native delegable functions (e.g.,
Filter,Sum,GroupBy) written directly in the data source expression.
Common Pitfalls and Troubleshooting
| Mistake | Symptom | Fix |
|---|---|---|
| Enhanced component properties not enabled | Custom property parameters don’t appear | Toggle the setting in Advanced settings |
| Parameter data type mismatch (e.g., passing a text string) | The function returns blank or an error | Ensure callers pass numeric values, or use Value() to convert |
| Optional parameter without a default value | The function fails when the parameter is omitted | Always provide a default (e.g., 0 for numbers) |
| Component not placed on the screen | The function name isn’t available for IntelliSense | Insert the component from the Insert pane |
| Division by zero (rate = 0) | The function returns a long decimal error | Use the If check shown above to handle zero rate |
If the label stays blank, check the formula for misspelled parameter names or missing parentheses. The built‑in formula analyzer often highlights syntax errors.
Recommendation
Start building your own library of custom functions today—even while the feature is experimental. The ability to package logic once and call it from anywhere reduces errors, speeds up development, and makes your apps easier to maintain. Share your components across projects by publishing them to a component library.
What function will you create next? A text truncation utility, a business‑day calculator, or a dynamic discount engine? The pattern shown here works for any input–output transformation.
References
- Original article: Matthew Devaney’s Power Apps Custom Functions & Reusable Code
- Microsoft Learn: Enhanced component properties in Power Apps Canvas
Learn how small coding practices—like using descriptive names, flattening conditions, and simplifying logic—can make your apps easier to update and less error-prone.
Move past the gallery and discover the hidden patterns for validation, navigation, and smart submission handling in your data entry forms.
PowerShell unlocks admin capabilities that the Power Platform admin center simply doesn’t offer—from recovering deleted apps to blocking trial licenses. Here’s how to wield them safely.