Results 1 to 5 of 5
  1. #1
    johnberman is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    3

    Query and Counting

    Hi




    I have an access dbase with a single table

    Im interested in reporting so need totals, I can write a query that will count the number of machines in a dept like so

    SELECT [Computer Inventory].Department, Count([Computer Inventory].ID) AS CountOfID
    FROM [Computer Inventory]
    GROUP BY [Computer Inventory].Department;

    This works fine, however I now want to add more so are two fields
    To_be_migrated
    Is_migrated

    These are just checkboxes so I assume criteria is true or false

    I need a query which will give me

    The total number of machines by dept
    The total marked for migration
    The total migrated

    Just not sure where to start

    Regards

    John b

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Yes/No fields are really boolean fields, where Yes/True = -1 and No/False = 0.

    So you could just add them to your Aggregate Query, i.e.
    Code:
    SELECT [Computer Inventory].Department, Count([Computer Inventory].ID) AS CountOfID, Sum(To_Be_Migrated), Sum(Is_Migrated)
    FROM [Computer Inventory]
    GROUP BY [Computer Inventory].Department;
    If you don't link the fact that they may return as negative numbers, just multiply by -1.

  3. #3
    johnberman is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    3
    Thanks for that, one last question - how do I just multiply by -1 ?

    Regards

    John B

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Its really as easy as you think it might be:
    Code:
    SELECT [Computer Inventory].Department, Count([Computer Inventory].ID) AS CountOfID, Sum([To_Be_Migrated]*-1) as CountOfToBeMigrated, Sum([Is_Migrated]*-1) as CountOfIsMigrated
    FROM [Computer Inventory]
    GROUP BY [Computer Inventory].Department;

  5. #5
    johnberman is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    3
    Appreciated

    John B

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

Similar Threads

  1. Counting Columns in a Query
    By bellevue in forum Queries
    Replies: 2
    Last Post: 01-23-2013, 10:38 AM
  2. Counting TOP/first 10 in Query
    By undee69 in forum Queries
    Replies: 5
    Last Post: 11-20-2012, 09:20 AM
  3. Yes/No Check Counting in Query
    By Kennertoy in forum Queries
    Replies: 7
    Last Post: 05-20-2012, 09:00 PM
  4. Counting in Query
    By EdwinLawrence in forum Queries
    Replies: 3
    Last Post: 03-05-2012, 12:21 PM
  5. Help with counting Query
    By metalhead22 in forum Queries
    Replies: 8
    Last Post: 04-29-2009, 02:07 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