Power Apps: Use User Defined Types in Power Fx to Better Structure Your Data

Angelo GulisanoPower Apps4 hours ago15 Views

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.

What Are User Defined Types?

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.

Example: Managing Customer Data

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.

Good to know for UDTs

  • UDTs enable tables and records to be passed in and out of UDFs
  • UDTs also enable bulk conversion of JSON untyped objects to typed objects
  • At the time of writing this article, they are in preview. Please be careful
  • They must be enabled in the app settings under Experimental Features

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.

Considerations

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/

0 Votes: 0 Upvotes, 0 Downvotes (0 Points)

Leave a reply

Join Us
  • X Network2.1K
  • LinkedIn3.8k
  • Bluesky0.5K
Support The Site
Events
June 2025
MTWTFSS
       1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30       
« May   Jul »
Follow
Search
Loading

Signing-in 3 seconds...

Signing-up 3 seconds...