Solved

MS SQL 2000 Report Services. Conditional Counting

Posted on 2006-07-19
5
406 Views
Last Modified: 2008-02-01
Hello,

I don't exactly remember how it was called in Crystal Reports (I think it was running totals), but I can't find a similar function in MS Reporting Services. Simple totals are simple, just use Count(...), but if I need to add conditioning, it becomes a real pain as there is nothing I could find so far in Report Services themselves.

Normally, I would create a couple of extra columns in my query, where I'd put 1 and 0 for different conditioning using CASE and then SUM on the proper column, but in this case I've already got 5 extra columns and I'll need 5 more just with 1s and 0s... I will probably have to do it as I did it before, but at least I can try to find how to do it properly.

To summarize: I need to know how to count the number of rows in the set under a condition specified, e.g.:

count( Fields!MyValue.Value ) only where Fields!MhDate = Today() for example.

Thanks,
Yurich
0
Comment
Question by:Yurich
5 Comments
 
LVL 25

Expert Comment

by:Mr_Peerapol
ID: 17143536
Yes, in my opinion, I think SUM(CASE WHEN ... THEN 1 ELSE 0 END) is the [only good] way to do that.
(SELECT COUNT(*) FROM the_same_table b WHERE b.group_by_field = a.group_by_field AND b.another_field = some_condition) is look even longer.
0
 
LVL 21

Author Comment

by:Yurich
ID: 17143669
In fact, I found a solution of how to do it in the Report Services, here is a smiplified example:

=RunningValue(
      IIF(      Format( Fields!MyDate.Value, "dd/MM/yyyy" ) =
                  Format( Parameters!TheDate.Value, "dd/MM/yyyy" ) AND
                  Fields!days.Value > 20, 1, 0 ),
      sum, "grpTypes" )

if this running value is placed in a group footer, it will correctly calculate the number of records for a day specified in TheDate variable with the days field greater than 20. it is in fact a derivation of the query with cases, but a bit more clearer and doesn't depend on the sp I run for a dataset.

Regards,
Mik
0
 
LVL 11

Expert Comment

by:Ved Prakash Agrawal
ID: 17144391
hi can you give me sample example so that i can give the exact solution.
0
 
LVL 21

Author Comment

by:Yurich
ID: 17144758
For example, I have a record set returning from my sp that populate a dataset that has negative and positive values, I want to count the number of rows (in my report) where the value is only negative.

thanks,
yurich
0
 
LVL 1

Accepted Solution

by:
BooMod earned 0 total points
ID: 17582179
Closed, 500 points refunded.
BooMod
Special Ops Mod
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

813 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now