@rachel_bisland
Since StartsWith is delegable, you can put it in the prefilter.
With({_preFilter:
Filter('Pupil Records',
House=varHouse &&
Site = varSite &&
StartsWith(EnrolYear, varEnrolYear) &&
StartsWith(Escalated, ESCALATEDFILTERCALC.Text) &&
StartsWith(RecordStatus, STATUSFILTERCALC.Text) &&
StartsWith(CategoryMain, MAINCATFILTERCALC.Text) &&
StartsWith(CategoryOther, OTHERCATFILTERCALC.Text) &&
StartsWith(Complaint, COMPLAINTFILTERCALC.Text) &&
(StartsWith(FirstName, 'HO-PupilName-SearchBox'.Text) ||
StartsWith(Surname, 'HO-PupilName-SearchBox'.Text) ||
StartsWith(FormClass,'HO-PupilName-SearchBox'.Text)
)
)},
SortByColumns(
Filter(_preFilter,
Code in Pupils.Code &&
Date >= DateValue(DATEFILTERCALC.Text)
),
"Date", Descending, "SurName", Ascending
)
)
Also, if the prefilter (without the startswith functions) returns less than 2000 records, then you can take advantage of the non-delegable Search function to widen your search.
i.e.
With({_preFilter:
Filter('Pupil Records',
House=varHouse &&
Site = varSite &&
StartsWith(EnrolYear, varEnrolYear) &&
StartsWith(Escalated, ESCALATEDFILTERCALC.Text) &&
StartsWith(RecordStatus, STATUSFILTERCALC.Text) &&
StartsWith(CategoryMain, MAINCATFILTERCALC.Text) &&
StartsWith(CategoryOther, OTHERCATFILTERCALC.Text) &&
StartsWith(Complaint, COMPLAINTFILTERCALC.Text)
)
)},
SortByColumns(
Search(
Filter(_preFilter,
Code in Pupils.Code &&
Date >= DateValue(DATEFILTERCALC.Text)
),
'HO-PupilName-SearchBox'.Text, "FirstName", "Surname", "FormClass"
),
"Date", Descending, "SurName", Ascending
)
)
It's all about balancing the number of records returned from the prefilter to be less than 2000.