Here is my go at this. I am making an assumption that what you want is mostly like the last screenshot you included in the question.
I pulled down the RDL you made available. Thanks for that! It can make this sort of thing that much easier.
The SQL in the report is mock data, which is good for what we are trying. I assume that the stored procedure that you are sourcing the data from now gives you something similar. I made a comment about getting the results into a temp table to work with, changing/shaping the data, and then returning it to the report. That is the tact I am going with in this answer.
Here is the updated SQL from the RDL, with a few line left out for brevity.
SELECT *
INTO #Report
FROM (VALUES(1,4,1,1,10,20,30),
(1,4,1,2,11,20,30),
…
(22,666,7,14,23,150,6)
) AS t(A, B, C, D,E,F,G);
SELECT A.A, A.B, A.C, A.D, A.E -- selecting columns A thru E
FROM #Report A
UNION ALL
SELECT DISTINCT B.A, B.B, B.C, B.F, B.G -- union in columns F and G
FROM #Report B
ORDER BY 1, 2, 3
DROP TABLE #Report
All this really does is use a SELECT INTO
to create a temp table with the original results. Then, I split the results, and UNION
it all back together with only the columns I need stacked on top of each other; also using a DISTINCT
where you want to get rid of duplication.
To use this in the RDL you provided, you will have to remove the F and G columns from the Tablix, and replace the SQL with this. This is what the Tablix would look like in design mode.
Now, you mentioned that there is a stored procedure that you cannot change. To get results from a stored procedure into a temp table you need to do 2 things.
First, create the temp table in the same shape at the results from the procedure. The tables doesn’t really have to be a temp table; you can make it a non-temp table and drop it later, too. In the temp table case, the DDL would look something like this:
CREATE TABLE #Report (A int, B int, C int, D int, E int, F int, G int)
Then you insert the results of the stored procedure into that temp table.
INSERT INTO #Report
EXEC usp_MyStoredProcedure
And no, there is no simple SELECT INTO
option with a stored procedure, in case you were wondering. A lot of people wish there was.
So, if this is the way you end up going, here is what the SQL for the report could be like.
CREATE TABLE #Report (A int, B int, C int, D int, E int, F int, G int);
INSERT INTO #Report
EXEC usp_MyStoredProcedure;
SELECT A.A, A.B, A.C, A.D, A.E -- grabbing columns A thru E
FROM #Report A
UNION ALL
SELECT DISTINCT B.A, B.B, B.C, B.F, B.G -- union in columns F and G
FROM #Report B
ORDER BY 1, 2, 3
This is what the report would look like in preview mode:
Hope this helps you out.