1

My tablix groups on one of its columns and only needs to output a list of time stamps for each row. As the time stamps are only two columns, that leaves an awful lot of wasted space.

Here is a basic mock-up of the current layout...

Current layout

... and this is the desired layout:

Desired layout

As shown, the report would ideally adjust dynamically to display half the rows of a group in the left "column" (including the extra row if uneven) and the remaining rows in the right "column". Is this possible with SSRS? If not as described, can you suggest something with a similar result?

Pablito
  • 79
  • 9

1 Answers1

3

You can do this with as long as your dataset can be updated to support it.

First I grabbed some sample datetime data I had and inserted it into a table variable called @t. You'll just need to swap out @t for your actual table name. This gave me the following enter image description here

Then I take this data and workout the row and column the data should sit in. In this example I am using a parameter to define the number of columns I want. You could do this and pass it in from your report if it's helpful, or just change it to a staic value. I'll demo with the parameter being passed in though.

Here's the query (Note you'll need to comment out the @Columns declaration if you want to pass this in from your report but for now we are just testing in SSMS or similar.

-- REPLACE @t with your actual tablename below
DECLARE @Columns int = 2 -- <= comment this out when you copy into your dataset query

SELECT 
    *
    , ColumnNum = ((SortOrder-1) % @Columns) + 1
    , RowNum = ROW_NUMBER() OVER(PARTITION BY GroupID, SortOrder % @Columns ORDER BY SortOrder)
    FROM(
        SELECT 
                ROW_NUMBER() OVER(PARTITION BY GroupID ORDER BY dt) as SortOrder,
                GroupID, dt
            FROM @t) x 
    ORDER BY GroupID, SortOrder

This gives us the following output

enter image description here

Now all we have to do is use a matrix control in the report to display it correctly.

  1. Create a new report
  2. Add a datsource and dataset
  3. Set your dataset query as above remember to comment out the DECLARE @Columns line if you want to parameterise it.
  4. Add a matrix control
  5. Drag RowNum to the 'Rows' placeholder, dt to the 'data' placeholder and finally select ColNum in the columns placeholder

The matrix should look like this (we're not finished yet...)

enter image description here

  1. In the row groups panel, drag GroupID above the exiting row group (above rownum in my example) so it creates a parent group.
  2. Finally, add a blank row inside the RowGroup group by right-clicking the rownum textbox and doing "Insert Row, Inside Group - Below". This will just give us a gap between groups

Note: I've changed the colour of the rownum and columnnum text boxes as we can delete these once testing is complete.

The final design should look like this.

enter image description here

When we run the report and set the parameter to 2 we get this

enter image description here

set it to 3 and we get this

enter image description here

You can now remove the top row and middle column to get rid of the row and column numbers. If you want to have a group header as in your sample. Add a row inside the group again but this time at the top and then add an expression to give your desired title.

Alan Schofield
  • 19,839
  • 3
  • 22
  • 35
  • Your detailed answer is much more than I could have hoped for. I didn't realise it when I asked, but it turns out I needed an additional group (sub-group if you will). I adapted your SQL accordingly and adjusted the tablix per the same logic. This has definitely helped me improve my SSRS skills. Thanks Alan! I am still having some trouble with the group header. In essence, I would like it to span all the columns of the matrix (merge the cells so to speak). I have had to settle with it being in a dedicated column to the left, but may have found a similar question. Will be trying it shortly. – Pablito Mar 03 '21 at 15:49
  • You can add a row within the GroupID group above the other rows, you shoudl be able to merge the cells as they are not in the details group and the set the expression to whatever you like – Alan Schofield Mar 03 '21 at 19:31
  • I'm don't think I'm getting it. In your last image, I would basically like the 3 column headers cells (containing 1, 2 & 3) to be merged and span the columns. I would then add a rectangle and textboxes to arrange the group data to make it presentable. However, the option to merge is only available for cells to the left of the double dashed lines (i.e. not part of the column group). – Pablito Mar 03 '21 at 21:24
  • AH Yes, as it's a Matrix not a Table, you can't merge cells across dynamic columns. You could do this using subreports. The subreport would accept a single GroupID parameter and only show the data for that group then the master report would simply have a table bound to a list of groups with the subreport on the detail row of the table. This would give you full control but if you need help with that, start a new question. – Alan Schofield Mar 04 '21 at 00:20
  • The subreport idea sounds good and I think I have enough to get started, but will need to park the idea for now. That will be for V2. :) Thanks again Alan! – Pablito Mar 04 '21 at 13:01