Multiple IIF Counts

R

Robbie Doo

When I do an IIf Count for one field it works fine but when I put a few
together I get an error. Example:

=Count(IIf(Field1]=1,0)) ...... works fine
=Count(IIf(Field1]=1,0)),Count(IIf([Field2]=5,0)) ..... gives errors

Anyway to put these two together?
 
F

fredg

When I do an IIf Count for one field it works fine but when I put a few
together I get an error. Example:

=Count(IIf(Field1]=1,0)) ...... works fine
=Count(IIf(Field1]=1,0)),Count(IIf([Field2]=5,0)) ..... gives errors

Anyway to put these two together?

You may know what result you are looking to get but we can't see your
computer, and your expression doesn't make sense, even just for the
one that you say works fine.
If the value of [Field1]=1 you wish to do what?
And what is the purpose of that last 0?

I think what you wish to do is count how many records show a 1 in the
[Field1] field. If that is so, then:
=Sum(IIf([Field1]= 1, 1, 0))

The above will add 1 for each record whose [Field1] = 1, giving you
the total count.

The second expression makes even less sense to me.
Are you trying to get the cumulative count of how many records in
[Field1] = 1 or [Field2] = 5?
Try:
=Sum(IIf([Field1] = 1 or [Field2] = 5, 1, 0))

If you mean something else, I'd suggest you post back with an example
to clarify what it is you want to accomplish.
 
R

Robbie Doo

Oh OK, here's what I'm looking for.

In a table I have different columns and I want to show each column's sum or
count in text boxes on a chart if conditions are met. For example, if a field
in column 1 is equal to 1 then count how many. The same rule goes for column
2 and so on...

fredg said:
When I do an IIf Count for one field it works fine but when I put a few
together I get an error. Example:

=Count(IIf(Field1]=1,0)) ...... works fine
=Count(IIf(Field1]=1,0)),Count(IIf([Field2]=5,0)) ..... gives errors

Anyway to put these two together?

You may know what result you are looking to get but we can't see your
computer, and your expression doesn't make sense, even just for the
one that you say works fine.
If the value of [Field1]=1 you wish to do what?
And what is the purpose of that last 0?

I think what you wish to do is count how many records show a 1 in the
[Field1] field. If that is so, then:
=Sum(IIf([Field1]= 1, 1, 0))

The above will add 1 for each record whose [Field1] = 1, giving you
the total count.

The second expression makes even less sense to me.
Are you trying to get the cumulative count of how many records in
[Field1] = 1 or [Field2] = 5?
Try:
=Sum(IIf([Field1] = 1 or [Field2] = 5, 1, 0))

If you mean something else, I'd suggest you post back with an example
to clarify what it is you want to accomplish.
 
F

fredg

Oh OK, here's what I'm looking for.

In a table I have different columns and I want to show each column's sum or
count in text boxes on a chart if conditions are met. For example, if a field
in column 1 is equal to 1 then count how many. The same rule goes for column
2 and so on...

fredg said:
When I do an IIf Count for one field it works fine but when I put a few
together I get an error. Example:

=Count(IIf(Field1]=1,0)) ...... works fine
=Count(IIf(Field1]=1,0)),Count(IIf([Field2]=5,0)) ..... gives errors

Anyway to put these two together?

You may know what result you are looking to get but we can't see your
computer, and your expression doesn't make sense, even just for the
one that you say works fine.
If the value of [Field1]=1 you wish to do what?
And what is the purpose of that last 0?

I think what you wish to do is count how many records show a 1 in the
[Field1] field. If that is so, then:
=Sum(IIf([Field1]= 1, 1, 0))

The above will add 1 for each record whose [Field1] = 1, giving you
the total count.

The second expression makes even less sense to me.
Are you trying to get the cumulative count of how many records in
[Field1] = 1 or [Field2] = 5?
Try:
=Sum(IIf([Field1] = 1 or [Field2] = 5, 1, 0))

If you mean something else, I'd suggest you post back with an example
to clarify what it is you want to accomplish.

re: >show each column's sum or count in text boxes <
There is a difference between Counting the number of times a value
appears in a column (a Field), and Summing a column's values. You seem
to be unclear as to which you want done. I'll guess you wish to count,
not sum the values.

Create a query that will be used as the chart control's rowsource.

Use the expression I gave you (without the = Sign).
CountField1:Sum(IIf([Field1] = 1, 1,0))
CountField2:Sum(IIf([Field2] = 5, 1,0))
etc....
Then use the new fields [CountField1] and [CountField2] in the chart
to display the field count.
 
R

Robbie Doo

Fredg:

I was able to come up with the following, however, the count doesn't come
out correct:

Counts: Count(IIf([Meds_Alerts]="Yes" And [Alrt_Status]="Not
Cleared",0,IIf([RDOnFile]="No",0,IIf([InfoUpdated]="No",0,IIf([SB87_Process]="No",0,IIf([SAVE_Doc]="No",0,IIf([SprtFrms]="No",0,IIf([MedsLeaderDiscr]="Yes",0,IIf([RedetDisp]=3,0)))))))))

Somewhere the information gets filtered I believe.

fredg said:
Oh OK, here's what I'm looking for.

In a table I have different columns and I want to show each column's sum or
count in text boxes on a chart if conditions are met. For example, if a field
in column 1 is equal to 1 then count how many. The same rule goes for column
2 and so on...

fredg said:
On Wed, 17 Sep 2008 10:33:01 -0700, Robbie Doo wrote:

When I do an IIf Count for one field it works fine but when I put a few
together I get an error. Example:

=Count(IIf(Field1]=1,0)) ...... works fine
=Count(IIf(Field1]=1,0)),Count(IIf([Field2]=5,0)) ..... gives errors

Anyway to put these two together?

You may know what result you are looking to get but we can't see your
computer, and your expression doesn't make sense, even just for the
one that you say works fine.
If the value of [Field1]=1 you wish to do what?
And what is the purpose of that last 0?

I think what you wish to do is count how many records show a 1 in the
[Field1] field. If that is so, then:
=Sum(IIf([Field1]= 1, 1, 0))

The above will add 1 for each record whose [Field1] = 1, giving you
the total count.

The second expression makes even less sense to me.
Are you trying to get the cumulative count of how many records in
[Field1] = 1 or [Field2] = 5?
Try:
=Sum(IIf([Field1] = 1 or [Field2] = 5, 1, 0))

If you mean something else, I'd suggest you post back with an example
to clarify what it is you want to accomplish.

re: >show each column's sum or count in text boxes <
There is a difference between Counting the number of times a value
appears in a column (a Field), and Summing a column's values. You seem
to be unclear as to which you want done. I'll guess you wish to count,
not sum the values.

Create a query that will be used as the chart control's rowsource.

Use the expression I gave you (without the = Sign).
CountField1:Sum(IIf([Field1] = 1, 1,0))
CountField2:Sum(IIf([Field2] = 5, 1,0))
etc....
Then use the new fields [CountField1] and [CountField2] in the chart
to display the field count.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top