Level and InScope Functions


Level([Scope]) returns a zero-based (top level in a hierarchy is 0) Integerthe current level of depth in a recursive hierarchy.

If Scope specifies a grouping with no Parent element, data set, or data region, Level returns . Child group, which specifies Parent, can only have a single group expression. If Scope is omitted, it returns the level of the current scope.

Level can be useful to provide indentation, for example, a hierarchy of employees in a sales department. To provide indentation, a designer needs to

  • Retrieve EmployeeId and ManagerID from a database.

  • Specify the hierarchy by setting the Parent of a group to ManagerId .

  • Specify padding as Padding.Left = (2 + Level()*20) & "pt" .

The InScope(Scope) function returns TRue if the current instance of an item is within the specified scope. Practical usability of InScope() is mostly limited to data regions that have dynamic scoping, such as Matrix and Chart.

To illustrate how scope works, let's capitalize on the example used previously for Matrix and change the detail cell to the following expression:

 = "Scope ="  + IIF(InScope("RG_SalesOrderNumber"), "RG_SalesOrderNumber," , "")  + IIF(InScope("RG_ItemName"), "RG_ItemName,", "") + IIF(InScope("RG_static"), "RG_static,", "") + IIF(InScope("CG_OrderQty"), "CG_OrderQty,", "") + IIF(InScope("CG_static"), "CG_static,", "") + IIF(InScope("matrix2"), "matrix,", "") + IIF(InScope("DataSet1"), "DataSet1,", "") + ")" 

Remember there are several groups in that example that denoted "RG" for row group and "CG" for column group. The same example also has the Matrix item and a data set.

You will see the resulting output similar to the following.

 Scope =                      Scope =    RG_SalesOrderNumber,         RG_SalesOrderNumber,    RG_ItemName,                 RG_ItemName,    RG_static,                   RG_static,    CG_OrderQty,  CG_OrderQty  ,    CG_static,                   CG_static,    matrix,                      matrix,    DataSet1                     DataSet1    Scope =                      Scope =    RG_SalesOrderNumber,         RG_SalesOrderNumber,  RG_ItemName,   RG_ItemName  ,        CG_OrderQty,  CG_OrderQty  ,    CG_static,                   CG_static,    matrix,                      matrix,    DataSet1                     DataSet1 

We have used strikethrough text to indicate information that is not presented on the actual output.

This example provides insight on Scope information and clearly identifies each type of cell on a Matrix. Table 12.1 presents a summary of the Scope .

Table 12.1. Scope of Cells in Matrix

Matrix's Element

Scope Inclusion

Dynamic row/column

Is included in each scope

Row subtotal

Is not included in CG_OrderQty scope

Column subtotal

Is not included in RG_ItemName

Total sum of all row subtotal or column subtotal

Is not included in RG_ItemName and CG_OrderQty scope


This knowledge allows developers to implement advanced formatting. For example, InScope() can be used to highlight rows with subtotals or to create a drill-through link with capabilities to access different reports , depending on the clicked cell.

Type a drill-through link expression in BackgroundColor of a Matrix's cell. This highlights the last row for an order:

 =IIF(Not InScope("RG_ItemName"), "LightGrey", "White") 



Microsoft SQL Server 2005 Reporting Services
Microsoft SQL Server 2005 Reporting Services
ISBN: 0672327996
EAN: 2147483647
Year: 2004
Pages: 254

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net