Dynemic Grouping in SQL Server Reporting Services 2012

  • Hello All,

    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

  • Hi.

    I am using a procedure or just a SQL-Statement like this:

    select

    -- dynamic row-grouplevel 1

    case

    when @paramRowGroupLevel1 = 1 then t1.Category

    when @paramRowGroupLevel1 = 2 then t1.ExecutiveName

    when @paramRowGroupLevel1 = 3 then t1.ClientName

    when @paramRowGroupLevel1 = 4 then ''

    else ''

    end AS GroupRow1,

    -- dynamic row-grouplevel 2

    case

    when @paramRowGroupLevel2 = 1 then t1.Category

    when @paramRowGroupLevel2 = 2 then t1.ExecutiveName

    when @paramRowGroupLevel2 = 3 then t1.ClientName

    when @paramRowGroupLevel2 = 4 then ''

    else ''

    end AS GroupRow2,

    -- dynamic col-grouplevel 1

    -- analog to the row-grouplevel

    sum( t1.sales ) sales

    from

    salestable t1

    where

    year = @paramYear

    -- (and ...)

    group by

    case

    when @paramRowGroupLevel1 = 1 then t1.Category

    when @paramRowGroupLevel1 = 2 then t1.ExecutiveName

    when @paramRowGroupLevel1 = 3 then t1.ClientName

    when @paramRowGroupLevel1 = 4 then ''

    else ''

    end,

    -- dynamic row-grouplevel 2

    case

    when @paramRowGroupLevel2 = 1 then t1.Category

    when @paramRowGroupLevel2 = 2 then t1.ExecutiveName

    when @paramRowGroupLevel2 = 3 then t1.ClientName

    when @paramRowGroupLevel2 = 4 then ''

    else ''

    end

    -- dynamic col-grouplevel 1

    -- analog to the row-grouplevel

    In the report the field GroupRow1 is the first grouped row. GroupRow2 is the second.

    If you wish to suppress the rows with empty values for GroupRow1 or GroupRow2 you could calculate the row-hidden-attribute.

    Hope this helps

    .akoeli

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply