Results 1 to 6 of 6
  1. #1
    accesscat is offline Novice
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    3

    Calculate value based on value in query and another table

    I'm trying to work out how to calculate a field in a query - I want to calculate detection rate (i.e number of detections at one site as calculated in the query divided by the number of nights that site was active). The number of nights the site was active is stored in a table. The query calculates number of detections per month, e.g.
    Site A June21 43
    Site B June21 21
    Site A July21 32
    Site B July21 15


    In my table of trap nights I have three fields - Site, MonthYear, TrapNights i.e.
    Site A June21 30
    Site B June21 25
    Site A July31 31
    Site B July31 10

    I want an expression in my query that calculates the detection rate for each site for each month i.e.
    Site A June21 43/30=1.43
    Site B June21 21/25=0.84
    Site A July21 32/31=1.03
    Site B July21 15/10=1.5

    How do I create an expression to calculate this? Thanks in advance.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Build a query that includes both tables with compound join on the site and date fields.
    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
    accesscat is offline Novice
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    3
    Thanks, can you provide an overview on how to do this please?

  4. #4
    Cottonshirt is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Feb 2018
    Posts
    116
    I want to calculate detection rate (i.e number of detections at one site as calculated in the query divided by the number of nights that site was active). The number of nights the site was active is stored in a table.
    if I understand you, you want to calculate the average number of detections by dividing a number in a query by a number in a table.

    to do that, open a query design window. in the Show Table dialogue select the query holding the number of detections, and the table holding the number of nights the site was active.

    join these two on the site name or number.

    then your calculation is [detections]/[nights active]

    be sure to use the correct division symbol for the type of answer you require.

    dividing like this \ gets you an integer
    dividing like this / gets you a decimal number


    good luck with your project


    Cottonshirt

  5. #5
    accesscat is offline Novice
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    3
    Thank you so much, that worked!

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Doesn't the join have to be compound - site and date fields?
    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.

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

Similar Threads

  1. Query to calculate summary from table.
    By SybRiN in forum Queries
    Replies: 5
    Last Post: 04-21-2017, 08:14 AM
  2. Replies: 2
    Last Post: 09-04-2013, 09:48 AM
  3. Replies: 11
    Last Post: 06-13-2012, 08:14 AM
  4. Replies: 34
    Last Post: 12-01-2011, 08:18 AM
  5. Replies: 0
    Last Post: 02-15-2009, 09:14 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