Results 1 to 7 of 7
  1. #1
    rtinsky is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    6

    Create 1 query from 5 queries


    I have 5 queries that all list the same data from my items table. But each query has different criteria for the calculated field Profit. How can I make this into one query. The criteria that each uses is <5, >4.99 and <20, >19.99 and <50, >49.99 and <100, >99.99 and <200, and >199.99. Here is one of the queries.

    SELECT Items.ID, Items.[Item Number], Items.[Item Title], Items.[Date Sold], [Items]![BIN Price]+[Items]![S&H Charged]-[Items]![Item Cost]-[Items]![S&H Cost]-[Items]![Ebay Fees]-[Items]![Paypal Fees]-[Items]![Tax] AS Profit
    FROM Items
    WHERE (((Items.[Date Sold]) Is Null) And ((Items![BIN Price]+Items![S&H Charged]-Items![Item Cost]-Items![S&H Cost]-Items![Ebay Fees]-Items![Paypal Fees]-Items!Tax)>4.99 And (Items![BIN Price]+Items![S&H Charged]-Items![Item Cost]-Items![S&H Cost]-Items![Ebay Fees]-Items![Paypal Fees]-Items!Tax)<20));

    My goal is to make a report from this query that can show the count total of each criteria. I am using Access 2010.

    Can anyone help me with this project?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,627
    Use those parameters to calculate a group identifier and use that field for sorting and grouping.

    Switch([Profit]<5,1, [Profit]>=5 And [Profit]<20,2, [Profit]>=20 And [Profit]<50,3, [Profit]>=50 And [Profit]<100,4, [Profit]>=100 And [Profit]<200,5, [Profit]>=200,6) As GroupID

    Create a group section in report based on the GroupID.

    Textbox in group footer can calculate the count:
    =Count([GroupID])

    Another can sum the Profit field:
    =Sum([Profit])

    The WHERE filter criteria is not needed and you have one query.
    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
    rtinsky is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    6

    your over my head

    I am not that skilled at access. I do not know how or where to put the switch line. I also don't know how to create a group section in a report. I do understand how to sum and count in the group footer. I used that in the 5 reports that use the 5 queries.

    Rodney

    Quote Originally Posted by June7 View Post
    Use those parameters to calculate a group identifier and use that field for sorting and grouping.

    Switch([Profit]<5,1, [Profit]>=5 And [Profit]<20,2, [Profit]>=20 And [Profit]<50,3, [Profit]>=50 And [Profit]<100,4, [Profit]>=100 And [Profit]<200,5, [Profit]>=200,6) As GroupID

    Create a group section in report based on the GroupID.

    Textbox in group footer can calculate the count:
    =Count([GroupID])

    Another can sum the Profit field:
    =Sum([Profit])

    The WHERE filter criteria is not needed and you have one query.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,627
    The Switch expression can be in query to create a field. Enter it on the Field row of the query designer grid:

    GroupID: Switch(...)

    If you have a group footer in the report then you have a group section.

    Access Help has guidelines on creating fields in query with expressions and on building reports with grouping & sorting.
    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.

  5. #5
    rtinsky is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    6
    Thanks so far. I got the switch command to work in the query. Now I just need to work on the report.

  6. #6
    rtinsky is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    6
    OK, I got the report to work. Thank you very much for your help! One last question. I only want to see the totals for each group. I do not want to see the details listed in this report. I am looking to run a report that will tell me on 1 page how many items are listed for each groupID. Is that possible?

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,627
    Options:

    1. set the Details section as not visible

    2. make the query a GROUP BY (Totals) aggregate instead of doing the report Grouping
    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. Replies: 15
    Last Post: 08-12-2011, 09:55 PM
  2. Replies: 5
    Last Post: 05-26-2011, 04:35 PM
  3. create a composed queries in access-sql
    By mosquito_admin in forum Queries
    Replies: 5
    Last Post: 01-25-2011, 12:42 PM
  4. Using queries to create new table
    By mradel in forum Queries
    Replies: 1
    Last Post: 10-26-2010, 10:34 PM
  5. automatically create queries
    By GEORGIA in forum Programming
    Replies: 8
    Last Post: 01-23-2006, 02:35 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