Previous Function (Reporting Services)
Returns the value or the specified aggregate value for the previous instance of an item within the specified scope.
(Variant or Binary) The expression that identifies the value to retrieve, for example, Fields!Fieldname.Value or Sum(Fields!Fieldname.Value).
(String) Optional. The name of a group or data region, or null (Nothing in Visual Basic), that specifies the scope from which to retrieve the previous value specified by expression. For more information about the scope parameter, see Using Built-in Report and Aggregate Functions in Expressions (Reporting Services).
Returns a Variant or Binary.
The Previous function returns the previous value for the expression evaluated in the specified scope after all sorting and filtering have been applied. If expression contains an aggregate function that uses a default scope, Previous aggregates the data within the previous instance of the scope specified in the aggregate function call. If expression contains an aggregate function that specifies a scope other than the default, the scope parameter for the Previous function must be a containing scope for the scope specified in the aggregate function call.
In a details group, use Previous to specify the value of a field reference in the previous instance of the detail row. Field references are only supported in the details group. For example, in a text box in the details group, =Previous(Fields!Quantity.Value) returns the data for the field Quantity from the previous row. In the first row, this expression returns a null (Nothing in Visual Basic).
In groups that are not detail groups, use Previous with an aggregate function such as First or Last that indicates a specific group instance. For example, in a text box in a row group based on =Fields!Year.Value, =Previous(First(Fields!Year.Value)) returns the year for the first instance of the Year group.
The functions Level, InScope, Aggregate and Previous cannot be used in the expressionparameter. Specifying the recursive parameter for any aggregate function is not supported.
The following code example, when placed in the detail data row of a data region, provides the value for the field LineTotal in the previous detail row.
The following example shows an expression that calculates the sum of sales on a specific day of the month and the previous value for that day of the month in a previous year. The expression is added to a cell in a row that belongs to the child group GroupbyDay. Its parent group is GroupbyMonth, which has a parent group GroupbyYear. The expression displays the results for GroupbyDay (the default scope) and then for GroupbyYear (the parent of the parent group GroupbyMonth).
For example, for a data region with a parent group named Year, its child group named Month, and its child group named Day (3 nested levels). The expression =Previous(Sum(Fields!Sales.Value,"Day"),"Year") in a row associated with the group Day returns the sales value for the same day and month for the previous year.
=Sum(Fields!Sales.Value) & " " & Previous(Sum(Fields!Sales.Value,"GroupbyDay"),"GroupbyYear")
The previous value for a field reference is only valid in a details group.