Create and update a collection in a canvas app

Use a collection to store data that users can manage in your app. A collection is a group of items that are similar, such as products in a product list. For more information about different types of variables such as collections: Understand canvas-app variables.

Prerequisites

  • Sign up for Power Apps, and then sign in by providing the same credentials that you used to sign up.
  • Create an app or open an existing app in Power Apps.
  • Learn how to configure a control in Power Apps.

Watch this video to learn how to create and update a collection:

Create a multicolumn collection

  1. In Power Apps Studio, add a Text input control.

    Insert a Text input control.

  2. Rename the control by selecting its ellipsis in the left navigation pane, selecting Rename, and then typing ProductName.

    Rename a control.

  3. Add a Drop down control.

    Add dropdown list.

  4. Rename the Drop down control Colors, and make sure that the Items property is selected in the property list.

    Items property.

  5. In the formula bar, replace DropDownSample with this expression:

    ["Red","Green","Blue"]

  6. Add a Button control, set its Text property to "Add", and set its OnSelect property to this formula:

    Collect(
        ProductList,
        {
            Product: ProductName.Text,
            Color: Colors.Selected.Value
        }
    )
    
  7. Press F5, type some text into ProductName, select an option in Colors, and then select Add.

    Preview of the app.

  8. Repeat the previous step at least two more times, and then press Esc.

  9. If you're using the preview version of Power Apps Studio, select the Variables pane and then select Collections to see the collections that you created.

    Show collections.

    If you're using the classic version of Power Apps Studio, on the File menu, select Collections.

    Show collection.

Show a collection

  1. Add a vertical Gallery control.

    Add a vertical gallery.

  2. Set the gallery's Items property to ProductList.

  3. In the Data pane, set the subtitle field to Color, and set the title field to Product.

    Set the gallery's Items property, and change the fields that it shows.

  4. Close the Data pane, select the gallery, and then set the Layout field to Title and subtitle.

    Change layout of the gallery.

    Your screen resembles this example:

    First screen example.

Remove one or all items

  1. Select the gallery template by clicking or tapping near the bottom of the gallery and then clicking or tapping the pencil icon near the upper-left corner.

    Select gallery template.

  2. Add a Trash icon to the gallery template.

    Add trash icon.

  3. Set the icon's OnSelect property to this formula:

    Remove(ProductList, ThisItem)

  4. Outside the gallery, add a button, set its Text property to "Clear", and set its OnSelect property to this formula:

    Clear(ProductList)

  5. While holding down the Alt key, select the Trash icon for an item to remove that item from the collection, or select the Clear button to remove all items from the collection.

Put a list into a collection

  1. Create a connection to a list created using Microsoft Lists.

  2. Add a button, and set its OnSelect property to this function, replacing ListName with the name of your list:

    Collect(MySPCollection, ListName)

    This function creates a collection that's named MySPCollection and that contains the same data as your list.

  3. While holding down the Alt key, select the button.

  4. (optional) To preview the collection that you created, select Collections on the File menu.

For information about how to show data from Microsoft Lists or SharePoint (such as dates, choices, and people) in a gallery: Show list columns in a gallery. For information about how to show data in a form (with drop-down lists, date pickers, and people pickers): Edit form and Display form controls.

Next steps