I have to create a SSRS report which should present both aggregated data and non-aggregated but thankfully not at the same time. I wonder if it's possible to do this in one stored procedure and in one report only.
The report has a dropdown list with values:
- Show aggregated
- Show non-aggregated
to let user decide which data to show.
Additionally data should be joined by CountryId
column.
I have a Finance
table which looks like:
FinanceId | CountryId | Year | I | II | III
----------+-----------+------+---+----+-----
1 | 1 | 2016 | 1 | 1 | 1
2 | 1 | 2016 | 2 | 2 | 2
//this is how I return grouped and summed data (there are many rows in this table, I left only two for better readability)
WITH CTE_Grouped1
(
SELECT
FinanceId, Year, I, II, III
WHERE
FinanceId = 1
)
, CTE_Grouped2
(
SELECT FinanceId, Year, I, II, III
WHERE FinanceId = 2
)
SELECT
CTE_Grouped1.FinanceId,
CTE_Grouped1.Year,
SUM(Grouped1.I),
SUM(Grouped1.II),
SUM(Grouped1.III),
SUM(Grouped2.I),
SUM(Grouped2.II),
SUM(Grouped2.III)
FROM
CTE_Grouped1
JOIN
CTE_Grouped2 ON CTE_Grouped1.CountryId = CTE_Grouped2.CountryId
GROUP BY
CTE_Grouped1.FinanceId, CTE_Grouped1.Year
//this is how I could return not aggregated data
SELECT * FROM Finance
My question is, how to return data the way the user chose.
The query is more complicated and it's not clear to me what should I do.
Should I create two separate reports or maybe there is a smart way, how to achieve this.