Any chance you could put the data in a collection?
I made an example here, although not with collection, but it would work:
Gallery.Items:
With(
{_data: Countries},
If(
IsBlank(gblSortBy),
SortByColumns(
_data,
"Title",
SortOrder.Ascending
),
SortByColumns(
_data,
$"{gblSortBy}",
SortOrder.Descending
)
)
)

SortButton.OnSelect:
Set(gblSortBy, TextInput1.Text)

