Results 1 to 7 of 7
  1. #1
    Ceichhorn is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Feb 2017
    Posts
    23

    Best way to count the number of records that have a specific field value?


    So I'm trying to do a calculation in the footer of a grouping, and in that calculation I need to know how many records had a specific value for a specific field, let's call it lngPropertyID. What is the best way to do this sort of calculation? For example, let's say this field could have a value of 1 or 2, and I wanted to calculate what percentage of the records in this group had lngPropertyID=1? Thanks in advance!

  2. #2
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    in a query you can do the total counts. qsTotal
    and finally in your data query ,join in the qsTotal into your data query.

    in the report footer put
    a field with the Total count All items, txtAllTotal
    and a field =Count(field) with the count of the 1 dept, txtDeptTot
    and finally a field to divide the two, =txtDeptTot/txtAllTotal
    set to pct.

  4. #4
    Ceichhorn is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Feb 2017
    Posts
    23
    Thanks andy! This allows me to count ALL records in a group, but it doesn't seem to provide a method to count all records that meet a specific requirement, e.g. where lngPropertyID=1. I tried putting that in to the count function as an argument and I got back the count of all records in the group, not just those that had lngPropertyID=1.

  5. #5
    Ceichhorn is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Feb 2017
    Posts
    23
    Quote Originally Posted by ranman256 View Post
    in a query you can do the total counts. qsTotal
    and finally in your data query ,join in the qsTotal into your data query.

    in the report footer put
    a field with the Total count All items, txtAllTotal
    and a field =Count(field) with the count of the 1 dept, txtDeptTot
    and finally a field to divide the two, =txtDeptTot/txtAllTotal
    set to pct.
    Ranman, thanks for the suggestion! When I do the count of the field, how do I get the count to recognize that I only want it to count records that contain a specific field value? If I put in =Count(txtDptTot="Example"), I get back a count of all records in the group, not just those that meet the criteria I'm providing.

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Try this...(The quick and dirty method.)
    In the footer, add two text boxes.
    Set the control source for the 1st text box to "= Sum(IIF(lngPropertyID = 1,1,0))"
    In the 2nd text box, set the control source to "= Sum(IIF(lngPropertyID = 2,1,0))"
    Obviously, do not include the quotes......

  7. #7
    Ceichhorn is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Feb 2017
    Posts
    23
    Quote Originally Posted by ssanfu View Post
    Try this...(The quick and dirty method.)
    In the footer, add two text boxes.
    Set the control source for the 1st text box to "= Sum(IIF(lngPropertyID = 1,1,0))"
    In the 2nd text box, set the control source to "= Sum(IIF(lngPropertyID = 2,1,0))"
    Obviously, do not include the quotes......

    This did it-thanks!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 16
    Last Post: 01-05-2016, 04:13 PM
  2. Replies: 5
    Last Post: 12-17-2014, 09:51 PM
  3. Count of specific number
    By samirmehta19 in forum Access
    Replies: 3
    Last Post: 05-20-2013, 02:29 PM
  4. Replies: 1
    Last Post: 04-04-2013, 11:59 AM
  5. Replies: 1
    Last Post: 01-24-2013, 05:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums