5
votes

Consider the following data source:

declare @Test table (EmpId int, ProdId int, Sold int)
insert @Test (EmpId, ProdId, Sold) values (1, 1, 1)
insert @Test (EmpId, ProdId, Sold) values (1, 2, 2)
insert @Test (EmpId, ProdId, Sold) values (1, 3, 3)
insert @Test (EmpId, ProdId, Sold) values (1, 4, 4)
insert @Test (EmpId, ProdId, Sold) values (2, 1, 5)
insert @Test (EmpId, ProdId, Sold) values (2, 2, 6)
insert @Test (EmpId, ProdId, Sold) values (2, 3, 7)
insert @Test (EmpId, ProdId, Sold) values (2, 4, 8)
select * from @Test

I create a Sql Server Reporting Services (SSRS) 2008 R2 report that contains a single Matrix configured like this:

|         | [ProdId]    |
| [EmpId] | [Sum(Sold)] |

Which, in preview mode, renders to the following (as expected):

|   | 1 | 2 | 3 | 4 |
| 1 | 1 | 2 | 3 | 4 |
| 2 | 5 | 6 | 7 | 8 |

But when I export it to CSV I get this:

| EmpId | ProdId | Sold |
| 1     | 1      | 1    |
| 1     | 2      | 2    |
| 1     | 3      | 3    |
| 1     | 4      | 4    |
| 2     | 1      | 5    |
| 2     | 2      | 6    |
| 2     | 3      | 7    |
| 2     | 4      | 8    |

In other words, when I export to CSV I lose the matrix layout and each row of data is rendered to a single row of CSV. Note that the report works as expected if I export to Excel, so this problem seems limited to CSV so far. I have tried restructuring the matrix as a table-within-a-table but that doesn't solve it either. Any suggestions?

3

3 Answers

4
votes

This is part of a big change to the report rendering between SSRS 2005 and SSRS 2008.

The only solutions I've found are:

  1. Export to Excel, then save the Excel document as CSV - This flattens the Excel format, and requires the groupings to be set up so that each row repeats the values of the parent groups. However, there are issues with exporting to Excel to begin with, such as is if consecutive rows contain the same data, the renderer sometimes omits the data, which can be stopped by setting the 'DataElementOutput' to True for the affected columns instead of 'Auto' which allows the renderer to guess what fields you may think are important.

  2. Build your report as a flat table - This pretty much defeats the point of making a matrix to begin with, and is a pain, but you can define the columns in advance, and can do so dynamically either in the query or using a lot of expressions in the textbox value and setting dynamic visibility on the columns. But to pull this off could potentially involve creating dozens or hundreds of columns to handle the potential appearance of a particular value.

  3. Don't upgrade to 2008 - If matrix reporting, and the formatting of the export, are business critical, there is really no good way to recreate the functionality in 2008, sticking with 2005 SSRS is the only sure-fire way to get the old rendering.

Resources:

1
votes

Here's an workaround:

  • Switch the source of CSV output to be an extra tablix which shows all the data as-is.
  • Disable the original tablix from outputting to CSV (Tablix > Properties > DataElementOutput > NoOutput).
  • Hide the extra tablix so it doesn't display. (Tablix > Right Click > Tablix Properties > Visibility > Hide).

This way you have full control of the display on-screen and of the CSV output.

0
votes

This works sometimes on SSRS 2016:

  1. Select the missing column(s)
  2. Open Properties
  3. Change Data Only -- > DataElementOutput as Output
  4. It varies where this operation works. For example when I did this on Tablix it didn't work, but it worked when I did this on the column. You could try create a table just to test if this works better after that. Unfortunately you can't make tables on footers, where this would be especially useful.