Method to round percentages in such a way that the total is always 100%.
In this example, the percentages (rounded to 1 decimal) are computed using ratio_to_report (colum Perc). The total of these is 100.1, which is mathematically correct, but of course not what we'd like to see.
The difference between 100.1 and the (ideal) 100 (column Perc Diff) is added to the row with the highest value (120).
In this example there are 2 rows with this highest value, so we have to force a winner.
For this I used rownum, because that allows the Descr column of rows to be identical without causing problems. A side effect is that the sorting can be a bit odd; in this case it causes the "x-120-b" row to be the winner that the difference is added to (and therefore the top row after sorting), which may not be what you want. If the Descr column is always a unique value in your case, you can change the "perc_count" line in "a" to this: