How to Add New Row in Power Apps Gallery Control?

Do you know how to add new row in Power Apps Gallery Control? Here, I will explain the various ways to add a new row in the Power Apps Gallery.

When using the Gallery in Power Apps, we frequently customize or apply conditional formatting based on our needs. One of the most common things users may desire or need from time to time is to add a new row to the gallery.

In this Power Apps article, I have explained two approaches to adding new rows in the Power Apps gallery. Such as:

  • Power Apps Gallery add a new row using the Patch Function
  • Power Apps Gallery add a new row using the Variable

How to Add New Row in Power Apps Gallery Control

Let us see how to add a new row in Power Apps Gallery Control. Check out the below examples.

Example – 1: [Using Power Apps Patch Function]

Unfortunately, We can not add a new row or item directly to the PowerApps Gallery control. There is no way to achieve this directly. Alternatively, we can use the PowerApps Patch Function. Let’s do this.

1. I have a Gallery control on the screen where the records are retrieved from a SharePoint List called Products. The list contains various fields with different Data types:

ColumnDatatype
TitleSingle line of text
VendorChoice
Customer NameSingle line of text
QuantityNumber
PriceCurrency
CommentsMultiline text

The SharePoint list looks like the below screenshot.

PowerApps gallery add new record

2. The screenshot below represents a Power Apps gallery control and a Button control (Create Item). The gallery contains the Title, Quantity, and Comments columns retrieved from the SharePoint list.

3. The button helps create a new record in the SharePoint list once the user clicks on it.

Power Apps gallery add new record

4. Select the Button and apply the below formula on its OnSelect property:

OnSelect = Patch(
    Products,
    Defaults(Products),
    {
        Title: "EarDope",
        Quantity: 5,
        Comments: "Nice Product"
    }
)

Where,

EarDope“, 5, “Nice Product” = Provide the new items/values

PowerApps gallery add new row

5. Now, Save and Preview the app. Tap on the Create Item button. Once you click on it, a new record has been created in the list, and the PowerApps Gallery control is shown below.

6. If the new record does not appear in the gallery control, refresh the SharePoint List data source connector. Then, you can view the new row in the gallery.

7. Meanwhile, if you go to the specific SharePoint list, the new item has also been added, as shown below.

PowerApps gallery add a new row

This is how to use the Patch function to add a new record in the Power Apps gallery control.

Example – 2: [Using Power Apps Variable]

1. Create a Power Apps Collection on App’s OnStart property:

OnStart = ClearCollect(
    colTravelDetails,
    {
        FullName: "James",
        Destination: "London",
        TravelDate: "16/10/2023"
    },
    {
        FullName: "Miriam",
        Destination: "Paris",
        TravelDate: "20/10/2023"
    },
    {
        FullName: "Delve",
        Destination: "Dubai",
        TravelDate: "25/10/2023"
    },
    {
        FullName: "Adele",
        Destination: "Australia",
        TravelDate: "30/10/2023"
    }
);

Where,

  • colTravelDetails = Collection Name
  • FullName, Destination, TravelDate = Collection Headers
  • James“, “London“, “16/10/2023” = Collection Records
How to Add New Row in Power Apps Gallery Control

2. Insert a Vertical Gallery Control and set its Items property as:

Items = colTravelDetails

colTravelDetails = Created Collection Name

Run the App’s OnStart property once. you can see the collection records as shown the image below.

Add New Row in Power Apps Gallery Control

3. Now set a variable and values on Screen’s OnVisible property:

OnVisible = Set(
    varNewTraveller,
    {
        FullName: "Harry",
        Destination: "USA",
        TravelDate: "02/11/2023"
    }
);

Where,

  • varNewTraveller = Variable Name
  • FullName, Destination, TravelDate = Collection Headers
  • Harry“, “USA“, “02/11/2023” = Add new record or value
Add New Row to Power Apps Gallery

4. Next, go to the App’s OnStart property and apply the code below:

OnStart = ClearCollect(colTravelNew,colTravelDetails);
Collect(colTravelNew,varNewTraveller);

Where,

  • colTravelNew = New Collection Name
  • colTravelDetails = Collection name that you have created before
  • varNewTraveller = Created Variable Name
Add a New Row in Power Apps Gallery

5. Select the gallery and set its Items property as:

Items = colTravelNew
Power Apps Gallery add new row

6. Save and Publish the app. Run the OnStart property of the App once. Then, the new record will be added to the gallery, as shown below.

PowerApps Gallery add a row

This is how to use the variable to add a new record in the Power Apps gallery.

Conclusion

Now I hope you have some idea to add new row in Power Apps Gallery Control. I have explained two methods to insert a new row into the Power Apps Gallery here. Such as:

  • Add a new row to Power Apps Gallery using the Patch Function
  • Power Apps Gallery add a new row using the Variable

Additionally, you may like some more Power Apps tutorials:

>