Results 1 to 9 of 9
  1. #1
    lkyinc is offline Novice
    Windows 10 Office 365
    Join Date
    Jan 2022
    Posts
    11

    Calculated field in a report pulling data from two separate columns in a query

    I have a database of all blood drives promoted by our organization. To look at a particular drive I query the date of that drive, then create a report based upon that query. For this post I will be dealing with two fields in the query: [Tag], and [Successful Donation], both are short text format. [Tag] indicates a regular blood donation with a "B", or a power red donation with a "P." [Successful Donation] indicates the result of attempt: Yes = blood was drawn, CG = could not give, C = Canceled, and NS = No show. I need an expression in a calculated field in the report that yields the count of the "Power Red donors" that were successful in their donation. In other words count the "P's" in the [Tag] column IF there is a corresponding "Yes" in [Successful Donation] column. Thank you for your help.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    =Count(IIf([Successful Donation]="Yes" AND [Tag]="P", "*", Null))

    This will have to be in report or group Header/Footer section.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Be aware that "Tag" is a reserved word in Access (Form property; Form Section property; Report property; Report Section property).
    Also, you should not use spaces in object names:
    [Successful Donation] -> better would be [Successful_Donation]-> best might be [SuccessfulDonation]

  4. #4
    lkyinc is offline Novice
    Windows 10 Office 365
    Join Date
    Jan 2022
    Posts
    11
    Quote Originally Posted by June7 View Post
    =Count(IIf([Successful Donation]="Yes" AND [Tag]="P", "*", Null))

    This will have to be in report or group Header/Footer section.
    THR 7:30PM CST - Copied expression and it ran, which is an improvement, but it returned 0 for an answer. The correct answer is 5. 7 donors presented but only 5 were successful donors. Thanks for the attempt.

  5. #5
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I just created a table, added fields "Tag" and "Successful Donation", added data.
    I created a form, added two text box controls bound to the two fields, set to Continuous Forms View.
    Added an unbound text box in the footer, set the control source to
    Code:
    =Count(IIf([Successful Donation]="Yes" And [Tag]="P","*",Null))
    Pressed F5 (refresh) and 3 was displayed. Added two more records with "P" and "Yes", pressed F5 (refresh) and 5 was displayed.


    Maybe post your dB? (change any sensitive data).

  6. #6
    lkyinc is offline Novice
    Windows 10 Office 365
    Join Date
    Jan 2022
    Posts
    11
    Thanks for your help. To post the DB do I just copy the table and paste here?

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Follow instructions from link at top of forum page: "How to attach files"
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    lkyinc is offline Novice
    Windows 10 Office 365
    Join Date
    Jan 2022
    Posts
    11
    Thanks Steve, Took the spaces out of the field names, but do not get the correct answer, even using your copied expression. When I run it, the result is 0. Kent

  9. #9
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Kent,
    So we know the formula works, now it is a matter of seeing your db for analysis.

    see the signature line in Post #2 -June7's post

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

Similar Threads

  1. Replies: 2
    Last Post: 03-28-2020, 08:46 AM
  2. Replies: 2
    Last Post: 09-17-2019, 08:38 AM
  3. Replies: 2
    Last Post: 06-02-2017, 09:30 AM
  4. Replies: 5
    Last Post: 04-17-2015, 11:04 AM
  5. Replies: 5
    Last Post: 03-29-2012, 09:21 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