7 Ways To Use The PATCH Function In Power Apps (Cheat Sheet)
7 Ways To Use The PATCH Function In Power Apps (Cheat Sheet) Posted by - Matthew Devaney on - June 12, 2022 93 Comments Power Apps PATCH function is the hard...
- Published
- Reading time
- 7 min read
Before you start
Is this guide for you?
- Best entry point
- Power Apps
- Time investment
- 7 min read
Imported reference from Matthew Devaney's blog for learning purposes. Original: https://www.matthewdevaney.com/7-ways-to-use-the-patch-function-in-power-apps-cheat-sheet/. Author: Matthew Devaney.
7 Ways To Use The PATCH Function In Power Apps (Cheat Sheet) Posted by - Matthew Devaney on - June 12, 2022 93 Comments
Power Apps PATCH function is the hardest function to understand. Why? The Patch function is the only function you can use 7 different ways. Yeah, you heard me right. Seven. That’s why I built a no-nonsense cheat sheet that you can use to quickly figure out how the patch function works.
Note: in all of the examples below the datasource called Employees where records are being created/updated is SharePoint list. Download Free PDF 😺 Table of Contents Create A New Record Update An Existing Record Get The Result Of The Patch Function Create Multiple New Records Edit Multiple Existing Records Upsert Multiple Records Change Values In A Record Variable
More Power Apps Patch Function Tips And Tricks
1. Create A New Record With Power Apps Patch Function Syntax
Patch(Datasource, BaseRecord, NewRecord) Input Employees Table In SharePoint ID FullName EmployeeNumber HireDate Active 1 Matthew Devaney 1050 05/28/2010 true 2 Alice Lemon 0958 11/03/2015 true 3 David Johnson 0563 08/15/2013 false Code Patch ( Employees , Defaults ( Employees ), {
FullName : "Sarah Green" , EmployeeNumber: 1002 , HireDate: Date ( 2018 , 3 , 14 ), Active: true } ) Code language: CSS ( css ) Output Employees Table In SharePoint ID FullName EmployeeNumber HireDate Active 1 Matthew Devaney 1050 05/28/2010 true 2 Alice Lemon 0958 11/03/2015 true 3 David Johnson 0563 08/15/2013 false 4 Sarah Green 1002 03/14/2018 true
2. Update An Existing Record Using Power Apps Patch Function Syntax
Patch(Datasource, BaseRecord, ChangeRecord) Input Employees Table In SharePoint ID FullName EmployeeNumber HireDate Active 1 Matthew Devaney 1050 05/28/2010 true 2 Alice Lemon 0958 11/03/2015 true 3 David Johnson 0563 08/15/2013 false 4 Sarah Green 1002 03/14/2018 true Code
Patch( Employees, LookUp( Employees, ID= 4 ), { FullName : "Sarah Brown" , EmployeeNumber : 1003 } ) Code language: JavaScript ( javascript ) Output Employees Table In SharePoint ID FullName EmployeeNumber HireDate Active 1 Matthew Devaney 1050 05/28/2010 true 2 Alice Lemon 0958 11/03/2015 true 3 David Johnson 0563 08/15/2013 false 4 Sarah Brown 1003 03/14/2018 true 3. Get The Result Of The Patch Function Syntax
Set(VariableName, Patch(Datasource, BaseRecord, ChangeRecord)) Input Employees Table In SharePoint ID FullName EmployeeNumber Created Created By … 1 Matthew Devaney 1050 05/08/2022 Matthew Devaney … 2 Alice Lemon 0958 05/10/2022 Matthew Devaney … 3 David Johnson 0563 05/13/2022 Matthew Devaney … 4 Sarah Green 1002 05/13/2022 Matthew Devaney … Code Set ( varEmployeeCurrent , Patch ( Employees , Defaults ( Employees ), {
FullName : "Kelly Smith" , EmployeeNumber: 1066 } ) ) Code language: CSS ( css ) Output Employees Table In SharePoint ID FullName EmployeeNumber Created Created By … 1 Matthew Devaney 1050 05/08/2022 Matthew Devaney … 2 Alice Lemon 0958 05/10/2022 Matthew Devaney … 3 David Johnson 0563 05/13/2022 Matthew Devaney … 4 Sarah Green 1002 05/13/2022 Matthew Devaney … 5 Kelly Smith 1066 05/29/2022 Matthew Devaney … varEmployeeCurrent record in Power Apps {
ID : 5 , FullName: "Kelly Smith" , EmployeeNumber: 1066 ,
'Created By' : Date ( 2022 , 05 , 29 ), Created: Matthew Devaney, Modified: Date ( 2022 , 05 , 29 ), Modified By: Matthew Devaney } Code language: CSS ( css )
4. Create Multiple New Records With Power Apps Patch Function Syntax
Patch(Datasource, BaseRecordsTable, NewRecordsTable) Input Employees Table In SharePoint ID FullName EmployeeNumber HireDate Active 1 Matthew Devaney 1050 05/28/2010 true 2 Alice Lemon 0958 11/03/2015 true 3 David Johnson 0563 08/15/2013 false 4 Sarah Green 1002 03/14/2018 true 5 Kelly Smith 1066 05/20/2022 true Code
ClearCollect( colNewEmployees, Table( Employees@{ FullName : "Mary Baker" , EmployeeNumber : 0798 , HireDate : Date ( 2022 , 06 , 06 ), Active : true }, Employees@{ FullName : "John Miller" , EmployeeNumber : 1203 , HireDate : Date ( 2022 , 06 , 11 ), Active : true }, Employees@{ FullName : "Susan Wright" , EmployeeNumber : 0590 , HireDate : Date ( 2022 , 06 , 23 ), Active : true
} ) ); Patch( Employees, ForAll( Sequence(CountRows(colNewEmployees)), Defaults(Employees) ), colNewEmployees ); Code language: JavaScript ( javascript ) Output Employees Table In SharePoint ID FullName EmployeeNumber HireDate Active 1 Matthew Devaney 1050 05/28/2010 true 2 Alice Lemon 0958 11/03/2015 true 3 David Johnson 0563 08/15/2013 false 4 Sarah Green 1002 03/14/2018 true 5 Kelly Smith 1066 05/20/2022 true 6 Mary Baker 0798 06/06/2022 true 7 John Miller 1203 06/11/2022 true 8 Susan Wright 0590 06/23/2022 true
5. Edit Multiple Existing Records Using Power Apps Patch Function Syntax
Patch(Datasource, BaseRecordsTable, UpdateRecordsTable) Input Employees Table In SharePoint ID FullName EmployeeNumber HireDate Active 1 Matthew Devaney 1050 05/28/2010 true 2 Alice Lemon 0958 11/03/2015 true 3 David Johnson 0563 08/15/2013 false 4 Sarah Green 1002 03/14/2018 true 5 Kelly Smith 1066 05/20/2022 true Code
ClearCollect( colUpdateEmployees, Table( Employees@{ ID : 2 , FullName : "Alice Henderson" , EmployeeNumber : 1001 }, Employees@{ ID : 4 , Active : false }, Employees@{ ID : 5 ,
HireDate : Date ( 2022 , 08 , 01 ) } ) ); Patch( Employees, ShowColumns( colUpdateEmployees, "ID" ), colUpdateEmployees ); Code language: JavaScript ( javascript ) Output Employees Table In SharePoint ID FullName EmployeeNumber HireDate Active 1 Matthew Devaney 1050 05/28/2010 true 2 Alice Henderson 1001 11/03/2015 true 3 David Johnson 0563 08/15/2013 false 4 Sarah Green 1002 03/14/2018 false 5 Kelly Smith 1066 08/01/2022 true
6. Upsert Multiple Records With Power Apps Patch Function Syntax
Patch(Datasource, BaseRecordsTable, UpsertRecordsTable) Input Employees Table In SharePoint ID FullName EmployeeNumber HireDate Active 1 Matthew Devaney 1050 05/28/2010 true 2 Alice Lemon 0958 11/03/2015 true 3 David Johnson 0563 08/15/2013 false Code
ClearCollect( colUpsertEmployees, Table( Employees@{ ID : 2 , FullName : "Alice Henderson" , EmployeeNumber : 1001 }, Employees@{ ID : Blank(), FullName : "Sarah Green" , EmployeeNumber : 1002 , HireDate : Date ( 2018 , 03 , 14 ), Active : false }, Employees@{ ID : Blank(), FullName : "Kelly Smith" , EmployeeNumber : 1066 , HireDate : Date ( 2022 , 05 , 20 ), Active : true
} ) ); Patch( Employees, colUpsertEmployees ); Code language: JavaScript ( javascript ) Output Employees Table In SharePoint ID FullName EmployeeNumber HireDate Active 1 Matthew Devaney 1050 05/28/2010 true 2 Alice Henderson 1001 11/03/2015 true 3 David Johnson 0563 08/15/2013 false 4 Sarah Green 1002 03/14/2018 false 5 Kelly Smith 1066 08/01/2022 true
7. Change Values In A Record Variable Using Power Apps Patch Function Syntax Patch(Record1, Record2) Input
Record stored in a global variable named gblEmployee ID FullName EmployeeNumber HireDate Active 1 Matthew Devaney 1050 05/28/2010 true Code Patch (
gblEmployee , { EmployeeNumber : 1063 } ); Code language: CSS ( css ) Output Employees Table In SharePoint ID FullName EmployeeNumber HireDate Active 1 Matthew Devaney 1063 05/28/2010 true
More Power Apps Patch Function Tips And Tricks
Want to learn more about the Patch function? Check out these awesome otherarticles I’ve written:
Everything You Need To Know About Power Apps Patch Forms
A full tutorial on how to build a Power Apps patch form including the topics: form submissions, data validation, error-handling and updating a previously submitted record.
Patch Multiple Records In Power Apps 10X Faster
A nifty trick I discovered to submit multiple records at once really really quickly.
Power Apps Patch Function Examples For Every SharePoint Column Type
Example of how to patch every SharePoint column type in an easy to read format. Patch Function Error-Handling
Learn how to check a form for errors on submission and eliminate the possibility to losing entered data. Power Apps Excel-Style Editable Table
Make an excel-style table in Power Apps you users will love by using the Patch function Did You Enjoy This Article? 😺
Subscribe to get new Power Apps articles sent to your inbox each week for FREE Enter your email address Sign Me Up Questions?
If you have any questions about 7 Ways To Use The PATCH Function In Power Apps please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion. Matthew Devaney M365 Copilot Power Apps
How To Create Copilot Custom UI Widgets In Power Apps
Tagged
Patch · Power Apps
Have a Microsoft 365 topic idea?
Share article suggestions, community session ideas, corrections, or real-world scenarios for future nxtM365 learning notes.
Keep learning Microsoft 365
Explore more practical guides for SharePoint, Power Platform, Copilot Studio, migration, automation, governance, and security.
Continue learning
Related tutorials
Related questions
Related comparisons
Next action