问题
Everyone, In SSRS, we have 2 columns as laid out below.
Sales | Running Sales 5.00 | 5.00 3.00 | 8.00 1.00 | 9.00
The distinction is that the first column (sales) is a is a grouping row and thus to get a Total for Sales per row, we are using =Sum(Fields!Sales.Value).
The problem occurs that when I try to use running value to get a running sales total. It gives me the SSRS error that Aggregate functions can only be used on page headers and footers. In this case it makes no sense to have the total in the footer. Does anyone know a solution/workaround to this problem.
Thanks.
回答1:
I had the same problem; here is how I solved it.
So here is how to subtotal a column that is itself a sum function. SSRS 2005 wont allow you to aggregate an aggregate function. For example, the total of a column showing a Running Total, useful in daily stock balance calculations. Add the following code to the report Report > Properties
Dim public totalBalance As Decimal
Public Function AddTotal(ByVal balance As Decimal) AS Decimal totalBalance = totalBalance + balance return balance
End Function
Public Function GetTotal() return totalBalance
End Function
This code adds two variables: totalbalance and cnt as decimal numbers. And two functions AddTotal
and GetTotal
.
AddTotal
allows items in rows to be added up, use as follows in a value cell, where you had;
=RunningTotal(Fields!ColumnName.Value,sum,nothing)
with
=Code.AddTotal(RunningTotal(Fields!ColumnName.Value,sum,nothing))
in the total cell, where it you were unable to simply use
=sum(RunningTotal(Fields!ColumnName.Value,sum,nothing))
use instead
=Code.GetTotal()
Simply add more variables and public functions if you need to sum the sum of more that one field.
http://blog.wingateuk.com/2011/09/ssrs-aggregate-of-aggregate.html
来源:https://stackoverflow.com/questions/13312308/sql-server-reporting-services-running-total-over-aggregated-data