You are currently viewing Nested collection in PowerApps :3 level
Nested collection

Nested collection in PowerApps :3 level

  • Post author:
  • Post category:Power Apps
  • Reading time:8 mins read

In this blog post we will learn how to create nested collection in PowerApps, and how to create multi record nested collection and how to expand Nested collection to one table in Power Apps.

PowerApps Collection

Collections in the Canvas App are considered a type of data source that used to store data locally in the app.

You can initialize a collection by using the ClearCollect() function and define the collection data.

ClearCollect(CollectionCol, {UserName: "ABC", email:"abc@gmail.com"})

For more details about the collection you can check these two articles:

Nested collection in PowerApps

The Power Apps Collection can take another collection as a field of its item , For example if you have a customer collection that contain information about the customers and information about the orders of this customer in this case the order is another collection that called Nested collection or a child collection.

How to create nested collection in PowerApps?

In this part we will learn how to create Nested collection in PowerApps inside the parent collection.

In the below formula we create a parent collection that called customerorderscol and this collection contain a field of nested collection for orders that called ordercol

ClearCollect(
    customerorderscol,
    {
        customername: "heba",
        ordercol: {
            orderid: 1,
            ordername: "order1"
        }
    },
    {
        customername: "Omar",
        ordercol: {
            orderid: 2,
            ordername: "order2"
        }
    }
)

The result of this formula is as shown in the below images.

Nested collection in PowerApps
The parent collection
how to create nested collection in powerapps
the Nested collection

Create multiple records in nested collection in PowerApps

To create Multi record in nested collection you can use the Table Function as shown below

ClearCollect(
    Multicustomerorderscol,
    {
        customername: "heba",
        ordercol:Table( {
            orderid: 1,
            ordername: "order1"
        },{
            orderid: 2,
            ordername: "order2"
        }
        )
    },
    {
        customername: "Omar",
        ordercol:Table( {
            orderid: 2,
            ordername: "order2"
        })
    }
)

This will result this collection

mult1 | Power Platform Geeks
Parent Collection
multi2 | Power Platform Geeks
Multi records nested collection in PowerApps

Multi nested collection and Datasource nested collection

In this example we will create more levels of nested connection and one of them is a collection from data verse table.

ClearCollect(
    nestedCollection1,
    {
        Title: "Level 1A",
        Level2: {
            Title2: "Level 2A",
            Level3: cities
            
        },Level3: cities
    },
    {
        Title: "Level 1B",
        Level2: {Title2: "Level 2B"}
    }
)
more1 | Power Platform Geeks
Level1
more2 | Power Platform Geeks
Level2
more3 | Power Platform Geeks
level3

This is how to create multi level nested collection in powerapps.

Nested collections to one table

In this example we will expand the nested collection in the Multicustomerorderscol collectio to one table and show them in Data table control

ShowColumns(
    Ungroup(
        Multicustomerorderscol,
        "ordercol"
    ),
    "customername",
    "orderid",
    "ordername"
)
Nested collections to one table
Expand Nested collections to one table

Return the nested collection of a record

LookUp(Multicustomerorderscol,customername="heba").ordercol

or

First(Filter(Multicustomerorderscol,customername="heba")).ordercol

both will return the nested collection of the customer name “Heba”.

re | Power Platform Geeks
See Also
Join us
Need Help
  • Have a related question? Please ask it at deBUG.to Community.

Heba Kamal

Microsoft MVP, MCT, Technical Speaker, Blogger, and Microsoft 365 and Power Platform Consultant.