@BHaapi
If you're receiving an error that the Sort function has invalid arguments, it suggests that there might be an issue with the fields you're attempting to sort or filter, or with the logic used in these functions.
Here's what you should check:
1. Check your data source: Ensure the fields 'Facility Initiated' and 'Created' actually exist in your 'MSPLocal' collection. Remember, PowerApps is case-sensitive, so make sure the field names match exactly.
2. Check the data types: Make sure 'Facility Initiated' is a Text field and 'Created' is a DateTime field.
3. Check your logic: '&&' is used to combine conditions in a logical 'and' operation. In the Sort function, you should use a comma to separate the field to sort by and the sort direction.
If you're still having trouble, you can try to break down the formula to identify at which point the error occurs.
1. Start by checking if you can filter the collection properly. Put this into a Label's Text property or just look at it in a gallery:
CountRows(Filter(MSPLocal, StartsWith('Facility Initiated', Facilitylookup1.Text)))
This should return the number of rows in the MSPLocal collection where 'Facility Initiated' starts with the text in Facilitylookup1. If this doesn't work, your issue is likely in the Filter function or in the 'Facility Initiated' field.
2. Next, add the sorting functionality. Change your Label or Gallery items property to:
First(Sort(Filter(MSPLocal, StartsWith('Facility Initiated', Facilitylookup1.Text)), Created, Ascending)).Created
This should return the earliest 'Created' date from the filtered items. If this doesn't work, your issue is likely in the Sort function or in the 'Created' field.
3. Add the text formatting. Change your Label or Gallery items property to:
Text(First(Sort(Filter(MSPLocal, StartsWith('Facility Initiated', Facilitylookup1.Text)), Created, Ascending)).Created, "m/d/yyyy h:mm")
This should return the earliest 'Created' date from the filtered items, formatted as "m/d/yyyy h:mm" (or whichever formatting you prefer to use).
If this doesn't work, your issue is likely with the Text function or the format string.
Remember to replace 'Facility Initiated', 'Created', 'MSPLocal', and 'Facilitylookup1' with your actual field and control names.
By breaking down and testing each part of the formula separately, you can identify at which point the error occurs and focus your troubleshooting efforts there.
See if it helps @BHaapi