I have to design table and the SSRS report that contains data in below format.
Please click on below URL to download excel sheet here
Once you downloaded the file, see the tab that contains RAW Data. It lists all the figures on row with rollover summation (ie states "AF", "GN" and "OZ") and months are separated by columns
The issue here is that the month should be generated dynamically based on current month. Hence right now the report shows data for September Month, but I am not sure how to store values for future month in database and how to show all months data in report.
Should I create table with all future months or should I mentions "Months" column dynamically?
Please note that USA states and rollover formula remains constant and I am able to write a query to generate states value.
The database structure I have thought of (& the reporting structure) is visible in Tab "Sample Report"
I am just trying what you have tried to do. i think you need to create column grouping for month. just try with below dataset for your ref.
CREATE TABLE #TEMP_RAW_DATA
(
N_id NUMERIC(18,0) IDENTITY(1,1),
VC_Country VARCHAR(30),
VC_States VARCHAR(50),
D_Date DATE,
I_Values INT
)
INSERT INTO #TEMP_RAW_DATA
(
VC_Country,VC_States,D_Date,I_Values
)
SELECT 'USA','Alabama','09-01-2019',57 UNION ALL
SELECT 'USA','Alabama','10-01-2019',47 UNION ALL
SELECT 'USA','Alabama','11-01-2019',69 UNION ALL
SELECT 'USA','Alabama','12-01-2019',1 UNION ALL
SELECT 'USA','Alabama','01-01-2020',42 UNION ALL
SELECT 'USA','Hawaii','09-01-2019',80 UNION ALL
SELECT 'USA','Hawaii','10-01-2019',55 UNION ALL
SELECT 'USA','Hawaii','11-01-2019',19 UNION ALL
SELECT 'USA','Hawaii','12-01-2019',73 UNION ALL
SELECT 'USA','Hawaii','01-01-2020',76 UNION ALL
SELECT 'USA','Massachusetts','09-01-2019',20 UNION ALL
SELECT 'USA','Massachusetts','10-01-2019',74 UNION ALL
SELECT 'USA','Massachusetts','11-01-2019',30 UNION ALL
SELECT 'USA','Massachusetts','12-01-2019',36 UNION ALL
SELECT 'USA','Massachusetts','01-01-2020',53 UNION ALL
SELECT 'USA','Pennsylvania','09-01-2019',53 UNION ALL
SELECT 'USA','Pennsylvania','10-01-2019',17 UNION ALL
SELECT 'USA','Pennsylvania','11-01-2019',1 UNION ALL
SELECT 'USA','Pennsylvania','12-01-2019',13 UNION ALL
SELECT 'USA','Pennsylvania','01-01-2020',42 UNION ALL
SELECT 'USA','Virginia','09-01-2019',26 UNION ALL
SELECT 'USA','Virginia','10-01-2019',24 UNION ALL
SELECT 'USA','Virginia','11-01-2019',29 UNION ALL
SELECT 'USA','Virginia','12-01-2019',79 UNION ALL
SELECT 'USA','Virginia','01-01-2020',73
SELECT VC_Country,VC_States,DATENAME(MONTH,D_Date) VC_Month,
CASE
WHEN PATINDEX('[a-f]%',VC_States)>0 THEN 'A-F'
WHEN PATINDEX('[g-n]%',VC_States)>0 THEN 'G-N'
WHEN PATINDEX('[o-z]%',VC_States)>0 THEN 'O-Z'
END VC_Group,
SUM(I_Values) I_Values
FROM #TEMP_RAW_DATA
GROUP BY VC_Country,VC_States,
CASE
WHEN PATINDEX('[a-f]%',VC_States)>0 THEN 'A-F'
WHEN PATINDEX('[g-n]%',VC_States)>0 THEN 'G-N'
WHEN PATINDEX('[o-z]%',VC_States)>0 THEN 'O-Z'
END,DATENAME(MONTH,D_Date)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.