Hi,
I decided to rewrite the Sorting function as I wanted another Screen to also have the sort function but I am having trouble getting it to work. I am still new to PowerApps and dont understand what isnt work. It is mostly likely because it is a copy of the code the PowerApps produce when you make an app with your data. The code that I added into the Gallery is working fine. (The code I got for it in the picture below.)
But the error I am getting is coming from the UpdateContext. (The code I got for it in the picture below.)

I did try reading the Microsoft Documents about the sorting function but it didnt really make sense.