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.
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
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"}
}
)
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"
)
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”.
See Also
- What are Microsoft Power Apps?
- PowerApps Variables Types : Context Variable Vs Global Variable Vs Collections
- Canvas App Collections
- How To Overcome PowerApps Delegation Limit?
- How To Use Power Automate?
- PowerApps Print Function, Forms, And Scrollable Galleries
- PowerApps Validation Examples On/before Submitting
- Share PowerApps With External Users / Guest Users
Join us
- Subscribe to Power Platform Geeks YouTube channel.
- Register to Saudi Arabia Power Platform User Group.
Need Help
- Have a related question? Please ask it at deBUG.to Community.