How To Patch A Single Record To A Table in PowerApps

In this blog, we are going to see how to use the patch function to create and update single records in a table. 

Create A New Record Using Patch Function

Syntax

Patch(Datasource, BaseRecord, NewRecord)

Code

Patch(
    GrosseryInventory,
    Defaults(GrosseryInventory),
    {
        Name: "Butter",
        ProductID: 1003,
        ExpiryDate: Date(2023,12,11),
        Price: 120
    }
)

Output

GrosseryInventory in SharePoint.

ID Name ProductID ExpiryDate Price
10 Pasta 1001 12/01/2023 110
11 Rice 1002 12/01/2023 99
12 Butter 1003 12/11/2023 120


Update An Existing Record Using Patch Function

Patch(Datasource, BaseRecord, ChangeRecord)

Code

Patch(
    GrosseryInventory,
    LookUp(
        GrosseryInventory,
        ID=12
    ),
    {            
        ExpiryDate: Date(2023,6,6),
        Price: 145
    }
)

Output

GrosseryInventory in SharePoint.

ID Name ProductID ExpiryDate Price
10 Pasta 1001 12/01/2023 110
11 Rice 1002 12/01/2023 99
12 Butter 1003 06/06/2023 145

That’s it, you have seen how to use the patch function to create and update single records in a table. Feel free to fill up the comment box below if you need any further assistance.