If you’ve built a Power App with any level of complexity, you probably know what it feels like to have data structures slowly fall apart. A few loosely grouped variables here, a bunch of nested records there, maybe some JSON scattered in between and before you know it, the app becomes hard to read and harder to maintain.
That’s where User Defined Types (UDTs) in Power Fx come in. This is a game-changer for anyone who wants to keep their app logic clean, consistent, and easier to work with especially when dealing with structured or reusable data.
In this article, I’ll walk you through what UDTs are, how I use them in real-world scenarios, and why I think they should be a default tool in your Power Apps toolbox.
User Defined Types (UDTs) are named, reusable data structures that you can define once and use throughout your app.
Think of them as typed records . For example:
type Address = {
Street: Text,
Zip: Text,
City: Text
};
Once defined, you can use this type in variables, components, collections, and even custom functions.
Feel free to write me if you need help.
Let’s say you’re building an app to manage customer profiles. Each customer has a name, a tax ID and Customer Code composed by “CC” and parts of TaxID and Year.
Without UDTs:
Set(
varCustomer,
{
Name: "John Doe",
TaxID: "DOEJHN80A01H501U",
CustomerCode: Concatenate(
"CC",
Left(
"DOEJHN80A01H501U",
4
),
"-",
Year(Now())
)
}
);
This works, but the structure is hardcoded, and if you need to reuse the same schema elsewhere, you’ll have to rewrite it manually every time. It’s easy to miss a field or make a typo and consistency suffers.
With UDTs, we can define a Type “Customer”:
Customer := Type ( {
Name: Text,
TaxID: Text,
CustomerCode: Text
});
And UDF (User Defined Function) to create New Customer:
newCustomer(name:Text,taxId:Text):Customer = {
Name: name,
TaxID: taxId,
CustomerCode: Concatenate(
"CC",
Left(
taxId,
4
),
"-",
Year(Now())
)
};
Then use them like this:
UpdateContext(
{
ctxCustomerMario: newCustomer(
"Mario",
"123AAA123BBB"
),
ctxCustomerLara: newCustomer(
"Lara",
"999BBB123CCC"
)
}
);
Cleaner, easier to read, and much more maintainable.
See official documentations:
User Defined Types are one of the best features to land in Power Fx in a long time. They bring clarity, scalability, and better architecture to app development, especially when building apps with reusable components and structured data.
I hope these information can help you! Leave me a comment to let me know what you think, or if you have a better idea to handle this case.
Contact me for questions! Have a nice day!
Original Post https://angelogulisano.com/power-apps-use-user-defined-types-in-power-fx-to-better-structure-your-data/