I have a SharePoint Online list named "Company attachments" and inside this, I have added different columns, including a date and time column [Attachement Created Date]. I want to sort and filter the Power Apps gallery based on the Dropdown selected value (Month). For that, I have created a collection like:
{ClearCollect(collMonths,{ID:1,Name:"Jun"});Collect(collMonths,{ID:2,Name:"Jul"});Collect(collMonths,{ID:3,Name:"Aug"});Collect(collMonths,{ID:4,Name:"Sep"});Collect(collMonths,{ID:5,Name:"Oct"});Collect(collMonths,{ID:6,Name:"Nov"});Collect(collMonths,{ID:7,Name:"Dec"});}
Till now, its fine, whenever I will try to sort the gallery based on the dropdown value, the gallery will not display the records and it will give the following delegation warning
My Items property code
{SortByColumns(Filter('Company Attachments',Month('Attachment Created Date')=Dropdown4.Selected.ID),"AttachmentCreatedDate",SortOrder.Ascending)}
Month
returns 1 for Jan, 2 for Feb and so on. Your collection has Jun as 1, Jul as 2 and so on. So with "Nov" selected, it is actually "June" (6). Could it be that there are no attachments in June?
You can also create your collection or variable with a Table...
Set(tMonth, Table(
{ ID:1, Name:"Jan"}, { ID:2, Name:"Feb"}, { ID:3, Name:"Mar"},
{ ID:4, Name:"Apr"}, { ID:5, Name:"May"}, { ID:6, Name:"Jun"},
{ ID:7, Name:"Jul"}, { ID:8, Name:"Aug"}, { ID:9, Name:"Sep"},
{ ID:10, Name:"Oct"}, { ID:11, Name:"Nov"}, { ID:12, Name:"Dec"}
));
// or
ClearCollect(collMonths, Table(
{ ID:1, Name:"Jan"}, { ID:2, Name:"Feb"}, { ID:3, Name:"Mar"},
{ ID:4, Name:"Apr"}, { ID:5, Name:"May"}, { ID:6, Name:"Jun"},
{ ID:7, Name:"Jul"}, { ID:8, Name:"Aug"}, { ID:9, Name:"Sep"},
{ ID:10, Name:"Oct"}, { ID:11, Name:"Nov"}, { ID:12, Name:"Dec"}
));
The delegation warning is worth reading up on (search for it). Essentially it means the filtering is done in PowerApps and not at SharePoint. So if you have more than 2,000 items (the max the PowerApps will pull in) then those after 2,000 will not be returned/filtered. What you can do, is create a new column in your SP List for Month number, it will have to be populated, can't be calculated. Then ensure this column is Indexed, then you can filter on it without delegation issues.