How to add row group headers to a "headerless" style report?

Martin Smith picture Martin Smith · Jun 7, 2014 · Viewed 13.6k times · Source

For the following Query

SELECT *
FROM (VALUES ('England','London',9787426),
             ('England','Manchester',2553379),
             ('Scotland','Edinburgh',452194),
             ('Scotland','Glasgow',1168270),
             ('Wales','Cardiff',447287)) V(Country, City, Population)

Creating a report from the Report Wizard (with the following options)

Report Wizard Options

constructs a report like

Report Wizard Generated

(Which Robert Bruckner calls "headerless" here)

When confronted with such a report structure is there any simple/non flaky way to convert it to the format below (with the Country header outside of the tablix body)?

i.e. without needing to delete the existing group, then re-adding it?

enter image description here

Answer

Anup Agrawal picture Anup Agrawal · Jun 11, 2014

Method 0:
If there is an existing table (or using wizard), there is no better way to do it than the one you explained. By deleting and readding the group.

Method 1:
You can design the tablix from scratch in report designer. Add the tablix, set the dataset and add the group.

Method 2:
The other way to do is modify the xml code(RDL).

Cleanup for your design: Remove the second row and add Country data element to detail row, so your design look something like this without the vertical merge and dotted lines.

enter image description here

To add group headers the way you want via the xml code you need to move the TablixCell from TablixRow to TablixRowHierarchy.:

  • Cut the TablixCell fragment under TablixRow->TablixCells containting your country data and keep it in seperate notepad/document.

  • Delete the corresponding TablixColumn under TablixColumns

  • RenameTablixCell Node to TablixHeader

  • Add the <Size>1in</Size> fragment between TablixHeader and CellContents

  • Paste the TablixHeader fragment under TablixRowHierarchy -> TablixMembers -> TablixMember in between SortExpression and TablixMembers.

  • Remove one of the <TablixMember /> fragment under the TablixColumnHierarchy. It should match the number of column in the report except the columns before the dotted lines (or before the dotted group).

TablixHeader element defines the header for the group.

TablixCells element defines the list of cells in a row of the body section of a Tablix

Here is the link to RDL specifications. It doesn't have 2012 version but the 2008 version still looks good.

Here is the schema diagram of Tablix from RDL specifications. When your data is in the TablixHeader then the columns will be in vertical merge and with the dotted lines outside the tablix row. When it is in the TablixCells it is part of TablixRow.

enter image description here