简体   繁体   中英

Dynamic Grouping in SSRS 2012

I am developing a report that have parameter like

RowGroupLevel1,
RowGroupLevel2,
ColumnGroupLevel1,
ColumnGroupLevel2,
ColumnGroupLevel3

Row Group Contain Category, Executive Name, Client Name Like Field Column Group Contain Year,Quarter,Month Field.
So My requirement is as like except Level1 in Row and Column Grouping other fields are optional.
For An Example : if I am selecting as below
scenario 1 :
RowGroupLevel1 - Category
RowGroupLevel2 - Executive Name
ColumnGroupLevel1 - Year
ColumnGroupLevel2 - Quaker
ColumnGroupLevel3 - Month

scenario 2 :
RowGroupLevel1 - Category
RowGroupLevel2 -
ColumnGroupLevel1 - Year
ColumnGroupLevel2 - Month
ColumnGroupLevel3 -

so as per above scenario how I can grouping my report dynamically.

Please help me to create any type of SSRS report.


Thanks in advance. Ankit Gusani

The easiest way to achieve this is to first of all write your query which pulls forward the results like this.

SQL Server Query

SELECT  DATEPART(WEEK,  Date_Column) AS [Weekly]
       ,DATEPART(MONTH, Date_Column) AS [Monthly]
       ,DATEPART(YEAR, Date_Column)  AS [Yearly]
       ,SUM(Some_Column)             AS Total
FROM Table_Name
GROUP BY DATEPART(MONTH, Date_Column) 
        ,DATEPART(WEEK,  Date_Column)
        ,DATEPART(YEAR, Date_Column)

SSRS Report

Add a Matrix Data region. Drag and drop Total column to DATA .

Create a Parameter say GROUP ON of Text type, and provide values

1) Weekly
2) Monthly
3) Yearly

Now below in ROW GROUPS pane, right click the only visible Row Group and goto GROUP PROPERTIES In GROUP ON section put following expression.

=SWITCH(
         Parameters!Groupby.Value = "Weekly",  Fields!Weekly.Value
        ,Parameters!Groupby.Value = "Monthly", Fields!Monthly.Value
        ,Parameters!Groupby.Value = "Yearly",  Fields!Yearly.Value
        )

Use the exactly same Expression on Data region ROWS section.

For Column name you can use the following Expression...

=SWITCH(
         Parameters!Groupby.Value = "Weekly",  "Weekly"
        ,Parameters!Groupby.Value = "Monthly", "Monthly"
        ,Parameters!Groupby.Value = "Yearly",  "Yearly"
        )

and you are good to go.

Important Note

SSRS is a cool tool for data presentation, not so cool when it comes to Data manipulation, to get better performance do all sorts of Data Manipulation closer to source (database, SQL Server).

All of the presentation stuff should be handled on SSRS.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM