Previous Function (Report Builder 2.0)

Returns the value or the specified aggregate value for the previous instance of an item within the specified scope.

Previous(expression, scope)


(Variant or Binary) The expression to use to identify the data and for which to retrieve the previous value, 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 (Report Builder 2.0).

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 does not contain an aggregate, the Previous function defaults to the current scope for the report item. For a text box in the details group, =Previous(Fields!Quantity.Value) returns the data for the field Quantity from the previous row. This expression in the first row returns a null (Nothing in Visual Basic). 

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.

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 default data row of a data region, provides the value for the field LineTotal in the previous 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")

Community Additions