# Data Scope in Expressions (Tutorial)

By following the steps below, you can build a sample report that will help you understand how the data scope inheritance works when using expressions.

1. Create a new report in the Web Report Designer.

2. Add a CSV Data Source to the report with the following data:

   ```CSV
   Product,Category,Amount
   Laptop,Electronics,1200
   Phone,Electronics,800
   Tablet,Electronics,400
   Headphones,Accessories,150
   Monitor,Electronics,300
   ```

   If you explicitly set the DataSource property of your report, it defines a report-level data scope, containing all rows. It defines the outermost scope. However, for this example, leave the Report.DataSource empty.

3. Add a Table: from the Components pane, drag a Table onto the design surface and bind it to your data source. A Table is a data item, so it switches scope to its own data source (data item-level scope). Everything inside its detail section is evaluated per row.

4. Add fields to columns:

   * Column 1:

     `=Fields.Product`

   * Column 2:

     `=Fields.Category`

   * Column 3:

     `=Fields.Amount`

   At this point `Fields.Amount` in a detail row represents the value from the current record and the default scope is the Table row (innermost detail scope).

    <img style="border: 1px solid gray;" src="/products/reporting/documentation/assets/c9222f0489f12ca7e1c43abeba9e4f22/bound-table.png" alt="Bound Table" />  

5. Preview the report.

    <img style="border: 1px solid gray;" src="/products/reporting/documentation/assets/d0e88c5f5a806d3ce3761ca75e9d964f/preview-table-without-groups.png" alt="Preview Table Without Groups" /> 

6. Add a Row Group by **Category** using the [Table Context Menu](https://www.telerik.com/products/reporting/documentation/designing-reports/report-designer-tools/web-report-designer/tools/table-context-menu).

    <img style="border: 1px solid gray;" src="/products/reporting/documentation/assets/3c2b9bd6b68deb4b5543f3bdbdc15723/table-context-menu.png" alt="Table Context Menu" />  
    <img style="border: 1px solid gray;" src="/products/reporting/documentation/assets/6565ff450004ebc130e5590c26ad9475/table-add-group.png" alt="Table Add Group" /> 

7. Save the group. This creates a new group-level scope (subset of rows that share the same Category). Here, the default scope is the current group instance, so all fields refer to that group’s records.

    <img style="border: 1px solid gray;" src="/products/reporting/documentation/assets/10d37fabaa58eaf593a86e0026efd56d/table-group-scope.png" alt="Table Group Scope" />  

8. Preview the report and see the products grouped by category:

    <img style="border: 1px solid gray;" src="/products/reporting/documentation/assets/c6d799484fde440e4d657a6300d5db48/preview-table-groups.png" alt="Preview Table Groups" />   

9. Add a Group Subtotal: In the Group Footer, select the TextBox under the **Amount** column and set the Value to `=Sum(Fields.Amount)`:

    <img style="border: 1px solid gray;" src="/products/reporting/documentation/assets/4d4191df265b5e295bef3f0d9241106f/group-footer-sum.png" alt="Group Footer Sum"  />  

   `Sum()` automatically aggregates over the group scope, not the entire dataset. This is because the nearest ancestor defining a data scope is the group. For **Accessories**, *Subtotal Amount is 150* and for **Electronics**, the *Subtotal Amount is 2700*:

    <img style="border: 1px solid gray;" src="/products/reporting/documentation/assets/77bf2abc50eb7e2a9c900570be1247d7/preview-group-footer-sum.png" alt="Preview Group Footer Sum" />   

10. Add a Group Grand Total: In the Table Group, select the TextBox above the **Amount** column and set the Value again to `=Sum(Fields.Amount)`. This is the same expression as the one set in the group's footer. However, the result is different due to the larger data scope.

     <img style="border: 1px solid gray;" src="/products/reporting/documentation/assets/770ba50f4e48467e93fd1c6f945a18d6/add-group-grand-total-sum.png" alt="Add Group Grand Total Sum" />  
     <img style="border: 1px solid gray;" src="/products/reporting/documentation/assets/98faf7bc34dca2f2e865cc8abf8f418a/preview-add-group-grand-total-sum.png" alt="Preview Group Grand Total Sum" />   

## See Also

* [Using ReportItem.DataObject](https://www.telerik.com/products/reporting/documentation/designing-reports/connecting-to-data/data-items/how-to-use-the-reportitem.dataobject-property-in-expressions)
* [Data scope related functions](https://www.telerik.com/products/reporting/documentation/designing-reports/connecting-to-data/expressions/expressions-reference/functions/data-functions)
* [Data Scope in Filters](https://www.telerik.com/products/reporting/documentation/wrd-user-guide/data-scope/data-scope-in-filters)
