I want to sort my collection by discount percentage for my sale category, I don't know if it is possible in Magento
You need to create a new attribute like
discount_per or something like this. Using Import assign percentage values in this attribute.
Now in attribute description on Storefront Properties tab Set "Used for Sorting in Product Listing" to "Yes" and save it.
Open category where you want your sorting.
Catalog -> Categories
Open your category, now open "Display settings" tab and set "Discount Per" in "Default Product Listing Sort By" dropdown (Discount per is the attribute that you have just created)
Now to add descending sorting, open tab "Design" and add this xml code here
<referenceContainer name="content"> <referenceBlock name="product_list_toolbar"> <action method="setDefaultDirection"> <argument name="dir" xsi:type="string">desc</argument> </action> </referenceBlock> </referenceContainer>
That would be all. Hope you find your solution