Count a specific value.

C

cage4000

Hi all,

I’m trying to make a text box return a “count†from another field that
contains a specific value. I want the text box to give me a count of all the
records that contain “2320†but it gives me the count for all the values
instead.

My Expression builder code is =Count([DepPlusSize]="2320")

Can anyone tell me what is wrong with my code?

Thanks,

Cage
 
A

Allen Browne

Try:
= - Sum([DepPlusSize] = "2320")

Omit the quotes if DepPlusSize is a Number field (not a Text field.)

The expression inside the brackets is True or False (or Null) for each
record. Access uses -1 for True, and 0 for False. Therefore summing the
expression gives the negative count of the cases where the expression is
True.
 
C

cage4000

That worked! Thank you Stefan and Allen for your help on this one.


Allen Browne said:
Try:
= - Sum([DepPlusSize] = "2320")

Omit the quotes if DepPlusSize is a Number field (not a Text field.)

The expression inside the brackets is True or False (or Null) for each
record. Access uses -1 for True, and 0 for False. Therefore summing the
expression gives the negative count of the cases where the expression is
True.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

cage4000 said:
Hi all,

I’m trying to make a text box return a “count†from another field that
contains a specific value. I want the text box to give me a count of all
the
records that contain “2320†but it gives me the count for all the values
instead.

My Expression builder code is =Count([DepPlusSize]="2320")

Can anyone tell me what is wrong with my code?

Thanks,

Cage
 
A

AccessNewbie

This worked perfectly on my report. Now, I would like also have my report
count from those "2320"s to also count if another field is "d". Further down
on my report I would also like to go one more so it will count if "2320" and
"d" and "yes" are all true. I hope this makes sense. I would like to take
this count one step further and count based on 2 fields (and then three). I
wasn't sure how to add the next phase. Any help is greatly appreciated.

Allen Browne said:
Try:
= - Sum([DepPlusSize] = "2320")

Omit the quotes if DepPlusSize is a Number field (not a Text field.)

The expression inside the brackets is True or False (or Null) for each
record. Access uses -1 for True, and 0 for False. Therefore summing the
expression gives the negative count of the cases where the expression is
True.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

cage4000 said:
Hi all,

I’m trying to make a text box return a “count†from another field that
contains a specific value. I want the text box to give me a count of all
the
records that contain “2320†but it gives me the count for all the values
instead.

My Expression builder code is =Count([DepPlusSize]="2320")

Can anyone tell me what is wrong with my code?

Thanks,

Cage
 
M

Marshall Barton

AccessNewbie said:
This worked perfectly on my report. Now, I would like also have my report
count from those "2320"s to also count if another field is "d". Further down
on my report I would also like to go one more so it will count if "2320" and
"d" and "yes" are all true. I hope this makes sense. I would like to take
this count one step further and count based on 2 fields (and then three). I
wasn't sure how to add the next phase. Any help is greatly appreciated.

Allen Browne said:
Try:
= - Sum([DepPlusSize] = "2320")

Omit the quotes if DepPlusSize is a Number field (not a Text field.)

= - Sum([DepPlusSize] = "2320" And field2 = "d")
= - Sum([DepPlusSize] = "2320" And field2 = "d" And field3 =
"yes")
 
A

AccessNewbie

thanks for the quick response. I have the query working but now I would also
like to know how to change the last AND to where it will only count if the
field is not null. Could you help with that?

Marshall Barton said:
AccessNewbie said:
This worked perfectly on my report. Now, I would like also have my report
count from those "2320"s to also count if another field is "d". Further down
on my report I would also like to go one more so it will count if "2320" and
"d" and "yes" are all true. I hope this makes sense. I would like to take
this count one step further and count based on 2 fields (and then three). I
wasn't sure how to add the next phase. Any help is greatly appreciated.

Allen Browne said:
Try:
= - Sum([DepPlusSize] = "2320")

Omit the quotes if DepPlusSize is a Number field (not a Text field.)

= - Sum([DepPlusSize] = "2320" And field2 = "d")
= - Sum([DepPlusSize] = "2320" And field2 = "d" And field3 =
"yes")
 
M

Marshall Barton

AccessNewbie said:
I have the query working but now I would also
like to know how to change the last AND to where it will only count if the
field is not null.

Marshall Barton said:
= - Sum([DepPlusSize] = "2320" And field2 = "d")
= - Sum([DepPlusSize] = "2320" And field2 = "d" And field3 =
"yes")


= - Sum([DepPlusSize] = "2320" And field2 = "d" And field3
Is Not Null)
 

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