Results 1 to 8 of 8
  1. #1
    sergi117 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2018
    Posts
    30

    Set up Countiif to count how many cells match with the corresponding data

    I'm trying to set up a column based on a count(iif select query which counts how many cells match with the single item. So essentially: count(iif(table1.column2<=table2.column3,1,0)
    If anyone could help please, thanks! I've tried writing up a query, but then I get aggregate issues.

    So if for example one
    Table 1 __________________________Table2
    Employee Pay _____________________column 1 __pay beg ______end
    1 _______15 ________________________x ________12 ________15


    2 _______20 ________________________x ________16 ________18
    3 _______25 ________________________x ________19 ________21

    The result should be
    Employee Pay __count
    1 _______15____2
    2 _______20 ____1
    3 _______25_____0

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    How are the tables related?
    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
    sergi117 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2018
    Posts
    30
    I just put the data up as an example, but essentially what I'm trying to do is related to payroll data. One table will contain hire dates, and the other will contain a set date from a beginning period to an end period. I need to get the total number of these periods where the hire date fits in. Like I said the table there was just to give an a more straight forward example.

  4. #4
    sergi117 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2018
    Posts
    30
    For excel it is rather simple just referencing data from another sheet, but I'm unsure about doing this for access.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    So tables do not have direct relationship. Options:

    1. Cartesian query - this is a query with no JOIN clause so every record in each table associates with every record of other table, then do an aggregate query with Count and IIf

    2. DCount() domain aggregate function
    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.

  6. #6
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    don't understand your example

    count(iif(table1.column2<=table2.column3,1,0)

    so result should be

    The result should be
    Employee Pay __count
    1 _______15____3
    2 _______20 ____1
    3 _______25_____0

  7. #7
    sergi117 is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2018
    Posts
    30
    that is right, I'm just stupid lol

  8. #8
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    ok - so as June says, you need a cartesian aggregate query - something like


    Code:
    SELECT Employee, Pay, Sum(iif(pay<=end,1,0)) as paycount
    FROM Table1, Table2 
    GROUP BY Employee, Pay
    note that words like end and count are reserved words - they are used in coding, so don't use these words

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

Similar Threads

  1. Countiif date with criteria in textbox
    By RAJESHKUMAR R in forum Forms
    Replies: 3
    Last Post: 04-21-2018, 07:14 AM
  2. CrossTab query Count() doesn't match.
    By elena in forum Queries
    Replies: 5
    Last Post: 05-13-2014, 12:24 PM
  3. How to enter data in multiple cells at once
    By kconsroe in forum Access
    Replies: 1
    Last Post: 11-07-2013, 08:37 AM
  4. How to unite cells with common data?
    By roeebicher in forum Queries
    Replies: 0
    Last Post: 02-07-2013, 05:11 AM
  5. Replies: 1
    Last Post: 12-21-2011, 02:11 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