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

后端 未结 1 783
臣服心动
臣服心动 2021-01-28 19:47

I need to display only top 10 Class based on Total (SUM(Premium)) column. I go to group ClassCode properties --> Filters and se

相关标签:
1条回答
  • 2021-01-28 20:18

    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.

    0 讨论(0)
提交回复
热议问题