Solved

MS SQL 2000 Report Services. Conditional Counting

Posted on 2006-07-19
5
400 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
Comment Utility
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
Comment Utility
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
Comment Utility
hi can you give me sample example so that i can give the exact solution.
0
 
LVL 21

Author Comment

by:Yurich
Comment Utility
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
Comment Utility
Closed, 500 points refunded.
BooMod
Special Ops Mod
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

772 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

12 Experts available now in Live!

Get 1:1 Help Now