//Collect the last 13 READING DATES for selected Site ClearCollect( colRecentDates, Filter( FirstN(Sort('[dbo].[dateTable]', readingDate,Descending),13), siteId = varSiteID ) );
//Collect the last all assets for the selected site ClearCollect( colAssets, Filter('[dbo].[assetTable]', dateId exactin colRecentDates.dateId) );
Thoughts on this one?
In and Exactin are delegable for SQL only when checking if a string is in another string. Today it is not delegable when checking if a record has membership against a table.
If you only have 13 records, you could use ForAll:
//Collect the last all assets for the selected site ForAll(RenameColumns(colRecentDates,"dateid","dateid_"), Collect( colAssets, Filter('[dbo].[assetTable]', dateId=dateId_) ) );
This means, "For each of the recent dates, collect the asset that matches each date until they're all collected."
When I use SQL Views, I also connect the original SQL tables for writing back data. You could keep them in for the relationships and use the View for all the Inner Joins you need.
Could you please show more details about the Delegation issue within your app?
The exactin operator is not a Filter and LookUp delegable predicate in SQL table data source. More details about the supported Filter and LookUp delegable predicates in SQL table data source, please check the following article:
As an alternative solution, you could consider take a try to save your assetTable SQL table records in to a Collection firstly, then use it as a data source within your second formula that you provided. Please take a try with the following workaround:
Set the OnVisible property of the first screen of your app to following formula:
Modify your second formula as below:
//Collect the last all assets for the selected site ClearCollect( colAssets, Filter(assetTableCollection, dateId exactin colRecentDates.dateId) )
then check if the issue is solved.
In addition, I also agree with @mr-dang's thought almost. More details about the Patch function, please check the following article:
Awesome advice, thank you @v-xida-msft. The assetTable will be very large and continuously growing so I don't think collecting the entire table is workable in this case. I'm working with @mr-dang's suggestion right now and it seems to be working as intended (though I'm not 100% certain yet).
I'm also looking at building a "bridge table" between the siteTable and assetTable with something like:
ClearCollect( colSiteAssets, AddColumns( colRecentDates, "readingDate", LookUp( colRecentDates, dateId = dateId, readingDate )), AddColumns( colRecentDates, "siteID", LookUp( colRecentDates, siteId = varSiteID, siteId ) ) );
This is almost like building a SQL View using PowerApps. But I can't quite get this one to work. I'll keep pecking away at it and post back the results.
@mr-dang, I'm confused by the...
It doesn't appear to actually rename the columns in either collection! Is this a trick to get the ForAll to parse through the colRecentDates collection? Or is it a best practice to not compare columns with the same names("dateid = dateid")?
How many records stored in your assetsTable SQL Table?
Actually, the amount of records you could store in a Collection is based on your computer's configuration. Someone user has made a test on this already, he could store about 4000 records within a Collection.
I found that there is a column called readingDate within your colRecentDates collection already, why do you add a new readingDate column into it using AddColumns function? I think it is not necessary.
In addition, the RenameColumns function would return a new table with the transform applied, the original table isn't modified. In other words, the RenameColumns(colRecentDates,"dateid","dateid_") formula would return a new table which has changed the dateid column into the dateid_ column, the original colRecentDates collection would not be modified.
More details about the RenameColumns function, please check the following article:
Within @mr-dang's case, the functionality of the RenameColumns function is similar to Disambiguation operator (@). Please check the following article for more details:
RE: Number of records stored in assetsTable:
RE: readingDate column and AddColumns function:
Thanks again! You are always VERY helpful and a huge asset to the community.
Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.
Check out the winners of the recent 'Can You Solve These?' community challenge!
Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.
Featuring samples like Return to the Workplace and Emergency Response Applications
Features releasing from October 2020 through March 2021