|
| 1 | +--- |
| 2 | +title: Bind a Report to a Transformation-Based Data Source |
| 3 | +author: Eugene Polevikov |
| 4 | +--- |
| 5 | + |
| 6 | +# Bind a Report to a Transformation-Based Data Source |
| 7 | + |
| 8 | +If you bind a report to a [JSON](bind-a-report-to-json-data.md), [Object](bind-a-report-to-an-object-data-source.md), [Entity Framework](bind-a-report-to-an-entity-framework-data-source.md), or [XPO](bind-a-report-to-an-xpo-persistent-object.md) data source that contains a collection property, you can flatten the data source structure: |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | +This tutorial illustrates how to use the **Federation Data Source**'s **Transformation** mode to flatten a JSON Data Source that contains a collection property. |
| 13 | + |
| 14 | +## Create a Report and Bind it to a Data Source |
| 15 | + |
| 16 | +1. [Create a new blank report](../add-new-reports.md) |
| 17 | + |
| 18 | +2. [Add a JSON data source](bind-a-report-to-json-data.md) |
| 19 | + |
| 20 | + This tutorial uses the following JSON string: |
| 21 | + |
| 22 | + ``` |
| 23 | + [ |
| 24 | + { |
| 25 | + "CategoryId": 1, |
| 26 | + "CategoryName": "Beverages", |
| 27 | + "Description": "Soft drinks, coffees, teas, beers, and ales", |
| 28 | + "Products": [ |
| 29 | + { |
| 30 | + "ProductId": 1, |
| 31 | + "ProductName": "Chai", |
| 32 | + "SupplierId": 1, |
| 33 | + "CategoryId": 1, |
| 34 | + "QuantityPerUnit": "10 boxes x 20 bags", |
| 35 | + "UnitPrice": 18.0000, |
| 36 | + "UnitsInStock": 39, |
| 37 | + "UnitsOnOrder": 0, |
| 38 | + "ReorderLevel": 10, |
| 39 | + "Discontinued": false, |
| 40 | + "Supplier": null |
| 41 | + }, |
| 42 | + { |
| 43 | + "ProductId": 2, |
| 44 | + "ProductName": "Chang", |
| 45 | + "SupplierId": 1, |
| 46 | + "CategoryId": 1, |
| 47 | + "QuantityPerUnit": "24 - 12 oz bottles", |
| 48 | + "UnitPrice": 19.0000, |
| 49 | + "UnitsInStock": 17, |
| 50 | + "UnitsOnOrder": 40, |
| 51 | + "ReorderLevel": 25, |
| 52 | + "Discontinued": false, |
| 53 | + "Supplier": null |
| 54 | + } |
| 55 | + ] |
| 56 | + }, |
| 57 | + { |
| 58 | + "CategoryId": 2, |
| 59 | + "CategoryName": "Condiments", |
| 60 | + "Description": "Sweet and savory sauces, relishes, spreads, and seasonings", |
| 61 | + "Products": [ |
| 62 | + { |
| 63 | + "ProductId": 3, |
| 64 | + "ProductName": "Aniseed Syrup", |
| 65 | + "SupplierId": 1, |
| 66 | + "CategoryId": 2, |
| 67 | + "QuantityPerUnit": "12 - 550 ml bottles", |
| 68 | + "UnitPrice": 10.0000, |
| 69 | + "UnitsInStock": 13, |
| 70 | + "UnitsOnOrder": 70, |
| 71 | + "ReorderLevel": 25, |
| 72 | + "Discontinued": false, |
| 73 | + "Supplier": null |
| 74 | + }, |
| 75 | + { |
| 76 | + "ProductId": 4, |
| 77 | + "ProductName": "Chef Anton's Cajun Seasoning", |
| 78 | + "SupplierId": 2, |
| 79 | + "CategoryId": 2, |
| 80 | + "QuantityPerUnit": "48 - 6 oz jars", |
| 81 | + "UnitPrice": 22.0000, |
| 82 | + "UnitsInStock": 53, |
| 83 | + "UnitsOnOrder": 0, |
| 84 | + "ReorderLevel": 0, |
| 85 | + "Discontinued": false, |
| 86 | + "Supplier": null |
| 87 | + } |
| 88 | + ] |
| 89 | + } |
| 90 | + ] |
| 91 | + ``` |
| 92 | + |
| 93 | +The [Field List](../report-designer-tools/ui-panels/field-list.md) displays the created JSON data source. |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | +## Create Data Federation and Transform the Data Source |
| 98 | + |
| 99 | +1. Click the report's smart tag, expand the **DataSource** property's drop-down menu, and click **Add Report Data Source**. |
| 100 | + |
| 101 | +  |
| 102 | + |
| 103 | +2. In the invoked **Data Source Wizard**, select **Data Federation** and click **Next**. |
| 104 | + |
| 105 | +  |
| 106 | + |
| 107 | +3. On the next page, click **Add Query**. |
| 108 | + |
| 109 | +  |
| 110 | + |
| 111 | +4. In the invoked [Query Builder](../report-designer-tools/query-builder.md), select the **Transformation** query type. Select the data source or query that contains columns you want to transform. Select the **Transform** check box next to the column you need to unfold and flatten. The bottom pane allows you to specify the aliases for the generated columns. |
| 112 | + |
| 113 | +  |
| 114 | + |
| 115 | + Click **OK** to create the query and click **Finish** to create the data source. |
| 116 | + |
| 117 | +The **Field List** displays the created Federation Data Source. |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | +## Prepare the Report Layout |
| 122 | + |
| 123 | +1. Set the **Landscape** orientation for report pages. Select the report and switch to the **Properties** panel. Enable the **Landscape** property. |
| 124 | + |
| 125 | +  |
| 126 | + |
| 127 | +2. Drop data fields from the **Field List** onto the report's [Detail](../introduction-to-banded-reports.md) band. Hold CTRL or SHIFT and click the fields to select multiple fields. |
| 128 | + |
| 129 | +  |
| 130 | + |
| 131 | +3. Add a **ReportHeader** band to the report. Right-click the report and select **Insert Band** / **ReportHeader**. |
| 132 | + |
| 133 | +  |
| 134 | + |
| 135 | +4. Create headers for the report columns. Select data fields and drop them onto the added **ReportHeader** band with the right mouse button. |
| 136 | + |
| 137 | +  |
| 138 | + |
| 139 | +5. Change header titles as necessary. Double-click a cell and type the new title. |
| 140 | + |
| 141 | +  |
| 142 | + |
| 143 | +6. Resize report columns. Select cells and drag their edges. |
| 144 | + |
| 145 | +  |
| 146 | + |
| 147 | +7. Change the header cells' appearance. Select cells and specify the following properties: |
| 148 | + |
| 149 | + | Property | Value | |
| 150 | + | --- | --- | |
| 151 | + | **Foreground Color** | White | |
| 152 | + | **Background Color** | DimGray | |
| 153 | + | **Padding** | 10, 10, 0, 0 | |
| 154 | + | **Font** | Arial, 9pt, style=Bold | |
| 155 | + |
| 156 | +  |
| 157 | + |
| 158 | +8. Change the band heights to match the table rows. Select the bands and drag their edges the same way as for the table cells. |
| 159 | + |
| 160 | +9. Add a style for the table's even rows. Select **TableRow2** in the **Properties** window, expand the **Styles** property, and select **New** for the **Even Style** property. Then select **Style1** and set the **Background Color** property to **216, 216, 216**. |
| 161 | + |
| 162 | +  |
| 163 | + |
| 164 | +10. Format the price values. Select the cell that displays the **Products_UnitPrice** value and set its [Format String] to **{0:c2}**. |
| 165 | + |
| 166 | +  |
| 167 | + |
| 168 | +The report is ready. Upper-level data source records are repeated as many times as there are flattened records: |
| 169 | + |
| 170 | + |
0 commit comments