# Create Master-Detail Reports with Tables

## Environment

<table>
	<tbody>
		<tr>
			<td>Product</td>
			<td>Progress® Telerik® Reporting</td>
		</tr>
	</tbody>
</table>

## Description

How can I create a Master-Detail report by using a Table report item that contains the detail data in Visual Studio Report Designer?

## Solution

To achieve the desired scenario:

1. [Create the master report](https://www.telerik.com/products/reporting/documentation/knowledge-base/create-master-detail-report-using-table#creating-the-master-report)
2. [Create the detail table](https://www.telerik.com/products/reporting/documentation/knowledge-base/create-master-detail-report-using-table#creating-the-detail-table)
3. [Configure the table filter](https://www.telerik.com/products/reporting/documentation/knowledge-base/create-master-detail-report-using-table#configuring-the-table-filter)

The master report data in this example consists of product categories from the AdventureWorks database. The detail table displays product names and numbers.

The example uses the [`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) to filter the detail table by a product category.

## Creating the Master Report

The master report will contain only a simple listing of product categories.

1. Create a new [Telerik Report Library](https://www.telerik.com/products/reporting/documentation/getting-started/about-telerik-reporting) to contain the report. As a result, the **Choose Report Type** dialog opens.

2. Select **Band Report Wizard** and enter a name for the report class.

3. On the **Choose Data Source** page of the Band Report Wizard, click the **Add New Data Source** button and select the [SqlDataSource Component](https://www.telerik.com/products/reporting/documentation/designing-reports/connecting-to-data/data-source-components/sqldatasource-component/overview). On the **Choose Your Data Connection** page of the wizard, set up the data connection to the AdventureWorks database, save it so you can use it later when creating the Table item. Click **Next**.

4. Enter the SQL statement below and click the **Next** button.

   ```SQL
   SELECT ProductCategoryID, Name FROM Production.ProductCategory
   ```

5. In the **Design Data Layout** page of the wizard, add the **Name** column to the detail section and click the Next button. Continue taking the defaults until you finish the Wizard.

## Creating the Detail Table

1. Resize the detail section to create some vertical space for the Table item.

2. Drag the **Table Wizard** item from the Visual Studio Toolbox to the detail section of the report.

3. On the **Choose Data Source** page of the Table Wizard, click the **Add New Data Source** button and select the [SqlDataSource Component](https://www.telerik.com/products/reporting/documentation/designing-reports/connecting-to-data/data-source-components/sqldatasource-component/overview). On the **Choose Your Data Connection** page of the wizard, select the already created data connection and click **Next**.

4. Enter the following SQL statement. Click **Finish**.

   ```SQL
   SELECT
   	P.Name,ProductID,ProductNumber,PC.ProductCategoryID
   FROM
   	Production.Product P,
   	Production.ProductSubcategory PS,
   	Production.ProductCategory PC
   WHERE
   	P.ProductSubcategoryID=PS.ProductSubcategoryID
   	AND PS.ProductCategoryID=PC.ProductCategoryID
   ```

5. In the **Arrange Fields** page of the Table Wizard, add the **ProductNumber** and **Name** fields to the Table columns and click the **Next** button. Continue taking the defaults until you finish the process.

## Configuring the Table Filter

This step creates a filter that uses the [`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) property to pass in the current `ProductCategoryID` for each record and the detail table prints all products that have that `ProductCategoryID`.

1. Select the Table item.

2. In the **Property** window, navigate to the **Filters** property and click the ellipses.

3. Click the **New** button to create a new filter. In the **Expression** drop-down for the filter, select `=Fields.ProductCategoryID`. Leave the operator at the default equals to (`=`) sign. In the **Value** property drop-down, enter the `=ReportItem.DataObject.ProductCategoryID` expression.

   ![The Edit Filters dialog of the Visual Studio Report Designer configured for filtering on the ProductCategoryID field from the parent data](https://www.telerik.com/products/reporting/documentation/assets/816e1f302fbc48edacf68baff30fa691/masterdetailtable0001.png)

4. Click the **OK**  button to close the dialog.

Click the **Preview** button to preview the report. Note that product numbers and names from the detail table are displayed under each product category from the master report.

![The Preview result in the Visual Studio Report Designer for the category Accessories](https://www.telerik.com/products/reporting/documentation/assets/90fbf4114450ce03871bbd773501b10f/masterdetailtable0002.png)

> tip You can create the same report layout with the [Standalone Report Designer](https://www.telerik.com/products/reporting/documentation/designing-reports/report-designer-tools/desktop-designers/standalone-report-designer/overview).
