How to display top 10 based on total amount in SSRS 2012

余生长醉 提交于 2019-12-02 07:39:07

In Group Properties add a sort and set

Sort by expression "=Sum(NetWrittenPremium)"
Order = "Z to A"

Them in the filter as follows:

Expression = "=Sum(NetWrittenPremium)"
Operator = Top N
Value = 10

Actually I've just noticed the Total row.... This will not calculate the total correctly and you cannot use aggregations in filters on the tablix (which would have worked otherwise).

You best bet would be to push this back to the server and do it there.

I can't test this on your data directly but it should work, I tested on someting similar...

SELECT r.* FROM 
    (SELECT d.* 
            , dense_rank() OVER(ORDER BY TotalNWP Desc) AS rnk
        FROM 
            (SELECT DISTINCT
                ClassCode, YearNum, MonthNum
                , SUM(t.NetWrittenPremium) OVER (PARTITION BY ClassCode, YearNum, MonthNum) AS NetWrittenPremium
                , SUM(t.NetWrittenPremium) OVER (PARTITION BY ClassCode) AS TotalNWP
             FROM cte_TopClasses t
            ) d
    ) r
    WHERE rnk <=10

Now there should be no need to do any filtering in SSRS, just sorting by the rnk column.

You only remaining problem is how to determine which of the last results (which all have the same total) take precedent over the others. You could do something like adding ClassCode to the dense_rank function to the are chosen alphabetically but that;s for yo to decide I guess.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!