Results 1 to 3 of 3
  1. #1
    therzakid is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2011
    Posts
    22

    Advanced CountIf Query

    Hello, I'm trying to determine the best method to perform a query that counts paired orders. I have a database with sales data, TVs and other components (dvd players, blueray disc players, and remotes) and want to know how often a tv is sold with another component. For instance, there should count 3 BDP players because there were 3 paired orders that sold a BDP with a TV. One was paired with a 22" and the other 2 were paired with the 40". One remote was paired with the same 40" tv that a BDP was, so the total 40" category is only 2, not 3. And the total 22" tv paired with one of the 3 column headings counted to only one. I've included the data below for reference.

    I'd really like to be able to do this on a big scale and hope that someone would be kind enough to take the time to help. Thank you!



    http://i1198.photobucket.com/albums/...id/dataimg.png

    Sample of the Query with relevant info (top table)



    Summary Table, I really need the totals for the different television sizes. But, only the televisions sold with one of the three header products. And, the totals for the column header items (dvd, bdp, remote) (bottom table)

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I was able to accomplish close to your desired results with:

    In the query that produced the example data you posted, include the following calculated fields.
    ItemCount: DCount("OrderNo","Table1","OrderNo='" & [OrderNo] & "'")
    Type: IIf(IsNumeric([SubCat]),"TV",[SubCat])
    SizeTV: DLookUp("SubCat","Table1","Category='TV' AND OrderNo='" & [OrderNo] & "'")

    Then do a Crosstab query.
    TRANSFORM Count(OrderNo) AS CountOfOrderNo
    SELECT SizeTV
    FROM Query1
    WHERE ItemCount>1
    GROUP BY SizeTV
    PIVOT Type;

    Note that any tv sizes that do not have data in the source query will not show a record in the Crosstab. To show other tv sizes would require a join in the source query to a master list of all possible tv sizes (or some other more creative solution).
    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
    therzakid is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2011
    Posts
    22
    Works great. Thank you very much for your help!

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

Similar Threads

  1. Countif in Access
    By Rosekv in forum Access
    Replies: 1
    Last Post: 06-19-2013, 05:58 AM
  2. advanced spreadsheets
    By arun2216 in forum Access
    Replies: 4
    Last Post: 04-22-2011, 07:48 AM
  3. Advanced Query
    By Cined in forum Queries
    Replies: 1
    Last Post: 03-04-2011, 03:40 PM
  4. Advanced Query
    By Exwarrior187 in forum Queries
    Replies: 6
    Last Post: 01-14-2011, 10:11 AM
  5. Similar to countif
    By JonHFL in forum Access
    Replies: 2
    Last Post: 06-04-2010, 10:55 AM

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