Solved

MS SQL 2000 Report Services. Conditional Counting

Posted on 2006-07-19
5
403 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

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…
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

947 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

21 Experts available now in Live!

Get 1:1 Help Now