Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Count Function Expand / Collapse
Author
Message
Posted Wednesday, June 25, 2008 1:31 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, April 16, 2013 7:12 AM
Points: 36, Visits: 109
I want to use count function on the field 'Status' - counting the records only if the value in the field is "C". I'm trying the following ways, but it just returns count of all the rows in status field.

=Count(Fields!Status.Value = "C")
OR
=IIF(Fields!Status.Value = "C", Count(Fields!Status.Value), 0)

could you please suggest?

thanks
Post #523668
Posted Wednesday, June 25, 2008 1:36 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, March 12, 2012 7:47 AM
Points: 138, Visits: 696
Try
=COUNT(IIF(Fields!Status.Value = "C", Fields!Status.Value, Nothing))


toolman
Numbers 6:24-26
Post #523677
Posted Wednesday, June 25, 2008 1:38 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, January 24, 2013 10:13 AM
Points: 20, Visits: 397
singhs2 (6/25/2008)
I want to use count function on the field 'Status' - counting the records only if the value in the field is "C". I'm trying the following ways, but it just returns count of all the rows in status field.

=Count(Fields!Status.Value = "C")
OR
=IIF(Fields!Status.Value = "C", Count(Fields!Status.Value), 0)

could you please suggest?

thanks


Try this:

=Count(IIF(Field!Status.Value="C", 1, 0))
Post #523680
Posted Wednesday, June 25, 2008 1:48 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, April 16, 2013 7:12 AM
Points: 36, Visits: 109
=COUNT(IIF(Fields!Status.Value = "C", Fields!Status.Value, Nothing))

worked for me, thanks

Now I have another addition to this.
How about if I need the two conditions-
Fields!Status.Value = "C" AND Fields!Race.Value = "W"

this statement is not working now!
could you please suggest

thanks a lot for all your help!
Post #523686
Posted Wednesday, June 25, 2008 1:50 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, March 12, 2012 7:47 AM
Points: 138, Visits: 696
Change your AND to OR. That should do it.

toolman
Numbers 6:24-26
Post #523691
Posted Wednesday, June 25, 2008 1:52 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, April 16, 2013 7:12 AM
Points: 36, Visits: 109
In other words, how would I write this count in the footer of reporting services-

select Count(*) From tableA Where status = 'C'
and race = 'B'
Post #523692
Posted Wednesday, June 25, 2008 2:03 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, April 16, 2013 7:12 AM
Points: 36, Visits: 109
It did work! I think I didn't refresh the first time!

=COUNT(IIF(Fields!Status.Value = "C" And Fields!Race.Value = "W", Fields!Status.Value, Nothing))
Post #523701
Posted Wednesday, June 25, 2008 2:04 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, March 12, 2012 7:47 AM
Points: 138, Visits: 696
Sorry. Didn't notice at first that you had different fields.
Try

=SUM(IIF(Fields!Status.Value = "C" AND Fields!Race = "W", 1, 0))

I think that should work for you.

Here's a couple good resources for expression writing:
http://msdn2.microsoft.com/en-us/library/ms157328.aspx
http://msdn2.microsoft.com/en-us/library/c157t28f(vs.71).aspx


toolman
Numbers 6:24-26
Post #523704
Posted Friday, August 26, 2011 11:37 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, March 11, 2013 10:18 AM
Points: 73, Visits: 238
=Count(IIf(Fields!sutastat.Value = "LA",1,0))
I only have 4 records with that status.
This still returns all rows.

When I try this:
=Count(IIf(Fields!sutastat.Value = "LA", Fields!sutastat.Value,Nothing))

I get zero

All i'm trying to do is this
select count(*) from employeecount where sutastat = 'la'
Post #1166329
Posted Friday, August 26, 2011 12:13 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, March 12, 2012 7:47 AM
Points: 138, Visits: 696
Try using SUM instead of COUNT.
SUM(IIF(your field Value = "LA",1,0))
This way it's summing ones or zeros instead of conditionally counting fields.


toolman
Numbers 6:24-26
Post #1166347
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse