Results 1 to 5 of 5
  1. #1
    akika is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2018
    Posts
    27

    access, queries for report display

    Hi,



    I have a table "Customers" with fields as short_text data type

    ID CustNum CustName Status Received_flag Category_Flag
    1 1234 Akira Active Yes
    2 5456 Kate Active No
    3 3555 Kim Inactive No Yes
    4 9823 Jane Active Yes No
    5 4563 Jim Active Yes Yes


    Pls help to build / change a query to get below data:

    SELECT DISTINCTROW Count(*) AS [Count Of Customers], Count(Customers.Status) AS CountOfStatus, Count(Customers.Received_flag) AS CountOfReceived_flag, Count(Customers.Category_Flag) AS CountOfCategory_Flag
    FROM Customers
    WHERE (((Customers.Received_flag)="Yes")) OR (((Customers.Category_Flag)="Yes")) OR (((Customers.Status)="Active"));



    Representations:

    Total Count Of records | Count Status Active | Count Category Flag Yes | Count Received Flag Yes | Percentage Category
    5 | 4 | 2 | 3 | %

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,523
    make 2 queries,Q1 to make value of the field result,
    Q2: count them

    Q1:
    select IIF([Active],1,0) as ActiveCt, IIF([Category_Flag]="Yes",1,0) as CataCt ... from table

    then Q2, sum the coumns:
    select sum(ActiveCt),Sum(CataCt) from Q1



  3. #3
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Since all fields are short_text data type this won't be very efficient:

    Code:
    
    SELECT Count(Customers.ID)                         AS CountOfCustomers, 
           Sum(IIf([Status] = "Active", 1, 0))         AS CountOfStatus, 
           Sum(IIf([Category_Flag] = "Yes", 1, 0))     AS CountOfCategory_Flag, 
           Sum(IIf([Received_flag] = "Yes", 1, 0))     AS CountOfReceived_flag, 
           [CountOfCategory_Flag] / [CountOfCustomers] AS PercentageCategory 
    FROM   Customers; 
    
    It would be better to use a foreign key to reference a customer, and to use a boolean for the received, category, and status flags. Even better still you might use integer datatypes instead of access' yes/no booleans: http://allenbrowne.com/NoYesNo.html

  4. #4
    akika is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2018
    Posts
    27
    thanks its working..
    I would like to add one more field Order_status containing values (Complete With change, Complete no change, Complete, Incomplete, Work in Progress, Pending)

    How can i amend this query to bring all completed values only (Complete With change, Complete no change, Complete).

  5. #5
    akika is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2018
    Posts
    27
    ive used like in the conditions .. looks ok thanks a lot

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

Similar Threads

  1. Replies: 1
    Last Post: 10-12-2017, 06:12 PM
  2. Replies: 3
    Last Post: 10-09-2017, 09:12 PM
  3. Replies: 6
    Last Post: 10-30-2012, 11:36 AM
  4. Replies: 3
    Last Post: 03-23-2011, 09:44 PM
  5. Replies: 3
    Last Post: 05-21-2010, 03:57 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