I have a main gallery which is populated by records in a collection which is in turn populated by data held in SQL table
The collection is filtered based on criteria in one of the fields in this collection. This collection contains a key field.
Another collection is made at the same time based on another SQL table which has a key in common with the primary table. The relationship is a 1 to many between the primary and secondary table.
I have successfully added a galley as an item in the main gallery linking the two with the common key. The secondary galley is then filtered to just one record, the record within the table with the highest key value from the matching secondary records (inthis case that is the most recent record of the many records)
All of this works and I can display data nicely in my gallery and its sub gallery.
My problem now is the user has asked can we sort by one of the fields displayed in the sub gallery, not a key field just a data field (contains a number of days something has been happening for, but could be anything really)
I have tried a number of ways but none have worked.
My closest and one that I think should work is by using a ForAll Loop on the main screen OnVisible property to loop through all the records in the main collection, finding the related related record I need from the secondary collection, getting the number field value I need and adding that as a new column in a third collection that just contains the fields I need from both matching records from the two tables. I can understand the logic for this but my code in PowerApps is not working, the records are made in the 3rd collection but the field I want just contains nulls. I have used As function to make sure the keys were recognised as coming from the two separate collections and making sure there was no ambiguity, but still no data in the field. If this worked then the data I need to sort by is in the main gallery's own columns and a standard sort by column will work.
Any help much appreciated.
Here is the code from the OnVisible property of the screen that contains the galleries
ClearCollect(colJAMMVoids,Filter('[dbo].[PROPERTY]',PropertyStatus = "Void"));
ClearCollect(colVoidDetails,'[dbo].[tblPropertyVoids]');
ClearCollect(colVoids,
ForAll(
colJAMMVoids As JV,
{
PropertyCode: JV.PropertyCode,
Address1: JV.Address1,
PropertyTypeID: JV.PropertyTypeID,
VoidDueDate: JV.VoidDueDate,
PDDisabledAdaption: JV.PDDisabledAdaption
NumberOfDaysVoid: First(
SortByColumns(
Filter(colVoidDetails As VD,VD.PropertyCode = JV.PropertyCode),"PropertyVoidsID",Descending)
).PropertyVoidsDays}
)
)