It can be very tricky to actually understand the details. You can get an idea by watching youtube videos such as: https://www.youtube.com/watch?v=yKl71IX8Zc0
Before calculation define you supply chain, then you can define the parameters for each phase and thereafter the calculation becomes easy.
The sorting is either on wafer level or device level depending upon the cost-trade-of between wafer cost/die size, yields and packaging cost.
The sorting is in principle two classes (bins): pass or fail. But in praxis you also have “continuety” and special parameter sets that enables to track trends.
In many cases you also have more pass bins – that can be to sort out high and low perfomance dies or devices.