Search code examples
sql-server-2008reporting-servicesgroupingssrs-2008-r2ssrs-tablix

SSRS Combine multiple group instances SQL Server Reporting Services-Grouping


I have the following SQL Server Report:

Bananas
--- Green --- 5
--- Yellow --- 10
--- Brown --- 1

Apples
--- Red --- 5
--- Gold --- 7
--- Green --- 2
Carrots
--- Orange --- 4
--- Brown --- 8
Potatoes
--- White --- 3
--- Brown --- 11

How do I go from that to this:
Fruit
--- Green ----7
--- Yellow ---10
--- Brown------1
--- Red--- ----5
--- Gold - - - 7
Vegetables
---Orange---4
---Brown---19
---White---3

Do I need to create a parent group(in the tablix) with a group by expression such as =IIF([Fields!FruitType].Value LIKE "Bananas" LIKE "Apples", "Fruit", "Vegetables")?


Solution

  • So... Creating the the input data

    SELECT  Type = 'Bananas' ,Color = 'Green' ,Total= 5 UNION ALL
    SELECT 'Bananas'  , 'Yellow', 10 UNION ALL
    SELECT 'Bananas'  , 'Brown' , 1  UNION ALL
    SELECT 'Apples'   , 'Red'   , 5 UNION ALL
    SELECT 'Apples'   , 'Gold'  , 7 UNION ALL
    SELECT 'Apples'   , 'Green' , 2 UNION ALL
    SELECT 'Carrots'  , 'Orange', 4 UNION ALL
    SELECT 'Carrots'  , 'Brown' , 8 UNION ALL
    SELECT 'Potatoes' , 'White' , 3 UNION ALL
    SELECT 'Potatoes' , 'Brown' , 11 
    

    rather than creating a group with that statement, Create a derived column in your resultset (or you could do it in TSQL?)

    enter image description here

    Then Create your group...

    enter image description here

    then preview...

    enter image description here