?
Solved

MS SQL 2000 Report Services. Conditional Counting

Posted on 2006-07-19
5
Medium Priority
?
417 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
[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
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
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.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Suggested Courses

765 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