Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

creating conditional groups in SSRS

Posted on 2010-11-14
5
Medium Priority
?
1,074 Views
Last Modified: 2012-06-21
Hello Experts,

I need to create 3 different groups in my report, based on a condition:

Group 1 -  AccountNumber like '400%'
Group 2 - AccountNumber like '42%' and '43%'
Group 3 - AccountNumber = '47100'

Can someone tell me how and where in SSRS I do this and what the syntax should be?

Thanks.
0
Comment
Question by:erp1022
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 21

Expert Comment

by:Yurich
ID: 34132006
Hello,

I presume your account number is your parameter (otherwise it will not work).
You can create conditional groups like that:

- In  your report, select a detail row, right click it and select Insert Group
- In the Group On area, select <Expression...>
- In the expression use the similar syntax:

=IIF( Parameters!AccountNumber.Value LIKE "400", Fields!Field1.Value,
 IIF( Parameters!AccountNumber.Value LIKE '42' OR Parameters!AccountNumber.Value LIKE '43', Fields!Field2.Value,
 IIF( Parameters!AccountNumber.Value = '47100', Fields!Field3.Value, Fields!Field4.Value )))

Field4 - is the field for all other accounts, but if your conditions cover all cases, then you can use this syntax:


=IIF( Parameters!AccountNumber.Value LIKE "400", Fields!Field1.Value,
 IIF( Parameters!AccountNumber.Value LIKE '42' OR Parameters!AccountNumber.Value LIKE '43', Fields!Field2.Value, Fields!Field3.Value ))

That should be all,
Good luck :)
0
 

Author Comment

by:erp1022
ID: 34132213
Hi,

Thanks for your response. No, I hadn't actually set up a parameter, I did not know that was required. I have worked with Crystal a lot and have just started working with SSRS, so please bear with me :)

So if I set up a parameter does that mean that the end user running the report will have to enter (or select) an account at runtime?

If so, is there another way to do this? I have no other paramaters on my report and the end user should not have to select anything at runtime.

Thanks again!
0
 
LVL 21

Accepted Solution

by:
Yurich earned 2000 total points
ID: 34132392
Hmmm...

I must have misunderstood what you really wanted to do. It seems to me that you don't actually want to create three groups, but rather one group (e.g. AccountType) with three (or four) values in it. In which case it's not done on the report side at all, but rather in your query.

Add an extra field to your query, similar to this:

SELECT...,
 CASE WHEN AccountNumber LIKE '400%' THEN 'AccountType1'
   WHEN( AccountNumber LIKE '42%' OR AccountNumber LIKE '43%' ) THEN 'AccountType2'
   WHEN AccountNumber = '47100' THEN 'AccountType3'
 ELSE 'AccountType4' as AccountType,
...


You can change values for the account types of course, and if you need AccountType4 only if your conditions do not cover all accounts (e.g. you can call it 'Other Accounts')

Then in the report, you can create one group and group it on the AccountType field. And that's it :)

Cheers


0
 

Author Comment

by:erp1022
ID: 34135549
This grouping thing in SSRS is not doing at all what I want it to do. What I want is to have three separate groups. Within those groups are the account numbers (based on the where condition) that show the revenue for whatever date range for that account number. So it would look like this:

GHS (these are the 400's)
     40010                          1,000.00
     40020                          5,000.00
     40030                          2,000.00
     and so on...
Total                                 8,000.00

HHG (these are the 42% and 43%)
     42000                         4,000.00
     42020                            100.00
     43000                         1,000.00
     and so on...
Total                                5,100.00

334 (this is the 47100)      500.00

Total Revenues              13,600.00


The account numbers pull a sum from the transactions table in the database based on the account number and date range.

The above I could do so easily in Crystal through the grouping function but this does not work similarly in SSRS. In Crystal I could insert different groups (based on the where condition) and add headers and footers to each group. Can you tell me how I should be doing this in SSRS?
0
 

Author Comment

by:erp1022
ID: 34136919
I think I got it, although it took a lot of playing around with it and trying different things. Thanks for your help!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this short article I will be talking about two functions in the SQL Server Reporting Services (SSRS) function stack.  Those functions are IIF() and Switch().  And I'll be showing you how easy it is to add an Else part to the Switch function. T…
A recent questions about how to add SSRS named instances, couldn't find any that talks about SQL server 2008, anyway I decided to help by creating some screen shots. The installation is straightforward, you just pop the SQL server 2008 installati…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question