Wednesday, December 19, 2012

SQL / SSRS - Selecting 95% and 99% (percentile) values

I was trying to generate a SSRS report where I wanted to display the 95% and 99% (percentile) values to remove the outliers.
Unfortunately there isn't a percentile function in SSRS unlike excel.

So I had to use SQL to derive these values.

To derive 95% value, select top 5% by ordering the counters of the instance in desc order. Now order these 5% in ascending order and select top 1
Select @95P = (select top 1 t.coulmnname from (select top 5 percent coulmnname from tablename order by columnname desc)t order by t.coulmnname asc)

To derive 99% value, select top 1% by ordering the counters of the instance in desc order. Now order these 1% in ascending order and select top 1
Select @99P = (select top 1 t.coulmnname from (select top 1 percent coulmnname from tablename order by columnname desc)t order by t.coulmnname asc)

No comments:

Post a Comment