A new feature in Power Apps is SQL Stored Procedures that can be called directly form the Power App. This will give you an UnTypedObject, but how do we type cast Tables? In this post the slow and the fast way.
SQL Server Stored Procedures
Table of Contents
A while back I wrote about the upcoming SQL Server Stored Procedure feature, but now it is fully available within Power Apps.

Type casting SQL Stored Procedure tables
First I’m going to have a look at the slow approach. The first part of the code that we need is call the stored procedure and with the Table function we convert this untyped object into a table.
dev.dboSelectAllMyRecords is my stored procedure that I specified in my Power App. The Stored procedure takes two parameters. In my can Param1 and Param2. These parameters are being set with two variables, varValue1 and varValue2. The Stored procedure will return a table of data with two properties. R_ID and R_Description.
Set(QueryResult,
Table(
dev.dboSelectAllMyRecords({Param1: varValue1,
Param2: varValue2 }
).ResultSets.Table1
);
ForAll(
Table(QueryResult),
Collect(
colMyCollection,
{
R_ID: Value(ThisRecord.Value.R_ID),
R_Description: Text(ThisRecord.Value.R_Description),
}
)
)
Then in the second part we convert each column to the type that we know the column should have. So in the above example, we have R_ID and R_Description being converted. R_ID is a number and R_Description is set to be a text property.
Yes this is the poor way of doing things, because if our Stored procedure returns 1000s of records a ForAll loop is the wrong thing to use.
Type cast tables faster
Using the AddColumns function we can type cast each column a lot faster. No looping through data, just copying the data structure and type casting it on the way is a lot faster.
Set(collRisk3, DropColumns(
AddColumns(
Table(QueryResult),
R_ID, Value(ThisRecord.Value.R_ID),
R_Description, Text(ThisRecord.Value.R_Description),
)
),
Value)
);
So how does this work?
Well one important note to take is that the unstructured objects appear within the Value property. Now with the above code we create new properties for each property of the objects in the Value array/collection/table. Then we create new properties and specify the expression as we did before. But this time we don’t use a ForAll, we use an AddColumns function.
Once all columns are created we drop the Value column, and now we have a formatted table.
So in this post we saw how to make Power Apps stored procedures return a table instead of an unformatted object.
Discover more from SharePains
Subscribe to get the latest posts sent to your email.

Hi Pieter, the explanation is a little hard to follow because the word “Value” is used in 4 different contexts. There is a function, a property, an array and columns. Is it possible to re-write in a way that is easier to follow?
Hi Mark,
Thank you for your comment. I have made some quick adjustments.
I’m testing the ForAll and AddColumns approches and both return <5000 rows in under 1 sec, AddColumns just under 100ms behind ForAll. In galery the items appear within seconds but with each button press galery poplation is faster in one or the other and it seems like random outcome.
Also, is there a particular reason why you set the Results.Table1 into variable and then parse it separately – could be done all at once and set the variable to final clear table instead?
I’ve separated that out mainly for blogging reasons. It is easier to explain small steps then multiple steps. You can indeed do that in one go.
Did you test the performance of both options? What was the actual performance speed gain?
Performance wise there is limited benefit, but development wise the second option is quicker.