How to Use the Patch Function in Power Apps: Step by Step
The Patch function is one of the most powerful tools in Power Apps: it lets you create and update records in a data source with full control, field by field, without relying on an automatic form. Knowing how to use Patch in Power Apps is essential when you need to save only a few fields, write to more than one table, or build custom edit screens. Unlike SubmitForm, which is tied to a form control, Patch works anywhere in the app.
Prerequisites
- An account with access to Power Apps to build a Canvas App.
- A connected data source, such as a SharePoint list or a Dataverse table.
- Basic knowledge of controls: screens, buttons, galleries, and text inputs.
Step 1: Connect the data source
Open your Canvas App and, in the Data pane, add the source where you will save records. In this example we use a SharePoint list called Contactos with three columns: Title (the name), Email, and Telefone. Once connected, the source is available by name in any formula. Also add three text inputs to the screen and rename them txtNome, txtEmail, and txtTelefone so the formulas are easy to read.
Step 2: Create a new record with Patch and Defaults
To create a record from scratch, we combine Patch with the Defaults function. Defaults returns an empty record with the source's default values, and Patch fills in only the fields we specify. Add a button and, in its OnSelect property, write:
Patch(
Contactos,
Defaults(Contactos),
{
Title: txtNome.Text,
Email: txtEmail.Text,
Telefone: txtTelefone.Text
}
)
When you click the button, a new item is created in the list with the values from the three text inputs. Note that the field names, to the left of the colon, must match the internal column names in the data source.
Step 3: Update an existing record
To update, we swap Defaults for the record we want to change. If the user picked a row in a gallery, the selected record is in Gallery1.Selected. A big advantage of Patch is that it touches only the fields you send: every other field stays exactly as it was.
Patch(
Contactos,
Gallery1.Selected,
{ Telefone: txtTelefone.Text }
)
Alternatively, you can find the record by its identifier with LookUp. This is handy when you stored the ID in a variable:
Patch(
Contactos,
LookUp(Contactos, ID = varId),
{ Email: txtEmail.Text }
)
Step 4: Validate before saving
Before saving, it is worth checking that the required fields are filled in. Use If with IsBlank so that Patch runs only when the data is valid:
If(
IsBlank(txtNome.Text),
Notify("Name is required.", NotificationType.Error),
Patch(Contactos, Defaults(Contactos), { Title: txtNome.Text })
)
This avoids incomplete records and gives the user a clear message when information is missing.
Step 5: Store the result and give feedback
The Patch function returns the record it created or changed. Store it in a variable with Set to reuse it, for example to show the generated ID, and let the user know with Notify. Finally, Reset clears the text input for the next record:
Set(
regGravado,
Patch(Contactos, Defaults(Contactos), { Title: txtNome.Text })
);
Notify("Contact saved successfully!", NotificationType.Success);
Reset(txtNome)
Verify the result
To confirm everything worked, open the data source (the SharePoint list or the Dataverse table) and check that the record appears with the correct values. Inside the app, add a gallery connected to Contactos: when you save, the new item shows up immediately in the list, because Power Apps refreshes the source automatically. If you used Notify, you should see the green success message at the top of the screen. If a column error appears, make sure the field names match those in the source.
Conclusion
With Patch you gain full control over how and when data is saved in Power Apps, something automatic forms do not always allow. From here, try saving to two sources with the same button, or using Patch with a collection to save several records at once. Which screen in your app will you simplify first with Patch?