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