Showing results for 
Search instead for 
Did you mean: 
Frequent Visitor

Patch function with variable as the Datasource

Hi. I am new to Powerapps


I have developed a small app which updates a sql table via an on premise gateway. Right now it is connected to a dummy table containing a small amount of data. 


I want to be able to declare the table/connection in a variable onStart so in future I would not have to go through each function to edit the DataSource. 

Original code:


    CountRows(colTaskUpdates) > 0,



I changed it to this thinking there would be no issues



    CountRows(colTaskUpdates) > 0,


In the Patch function with my code I get this message: "The first argument of 'Patch' should be a collection".
although the refresh function works with the variable.

Reading through the documentation I still could not find the answer to why the variable can not be passed. 


Thank you in advance



Super User
Super User


First, there is no need to issue a Refresh on your datasource.  In PowerApps, your datasource will already reflect any changes you make.  Issuing a refresh will just kill your performance.


Second, what you think is happening with the Refresh is not is not refreshing the datasource when in a variable.


Finally, you cannot use a variable as you are.  You have to specifically define the datasource.  Using variables like that is very "programmatic"  - PowerApps is not a programming platform.  It is not "code", it is just formulas like you would have in Excel (as it was designed after that).


I hope this is helpful for you.

Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!


Hi Randy. Thank you for your reply. 
I understand your reply but it does not add up for me. 


Finally, you cannot use a variable as you are.  


I tried the variable in other functions as well. This one works. 



 Also this one



So in the end for me it seems like it is only for the Patch function. And I still can not find an answer to why it is like this. 

Helpful resources

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.


New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (1,121)