Results 1 to 4 of 4
  1. #1
    SamuelOu is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2015
    Posts
    16

    Return Minimum value between 5 fields

    Hello,

    I have a table contains data like following:

    Qty1 Qty2 Qty3 Qty4 Qty5
    Item1 1 1 4
    Item2 3
    Item3 2 -1 0 4
    Item4 4 2 -2 3 5

    Is it possible using query to return the minimum value for each item, as:
    Qty
    Item1 1
    Item2 3
    Item3 -1
    Item4 -2



    I Google this question before posting, and seems the only answer is here: http://support.microsoft.com/kb/209857

    However, I don't understand it at all since I am lack of knowledge of SQL.

    Any help is appreciated. Thank you.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    That is not a normalized data structure.

    The VBA custom function is one approach.

    Could rebuild the db into a normalized structure. Table would be like:
    ItemID Category Quantity
    1 1 1
    1 2 1
    1 3 4
    2 1 3
    3 1 2
    3 2 -1
    3 3
    3 4 4
    4 1 4
    4 2 2
    4 3 -2
    4 4 3
    4 5 5


    A UNION query could rearrange the data into normalized structure to emulate that table:

    SELECT ItemID, 1 AS Category, Qty1 AS Quantity FROM tablename
    UNION SELECT ItemID, 2, Qty2 FROM tablename
    UNION SELECT ItemID, 3, Qty3 FROM tablename
    UNION SELECT ItemID, 4, Qty4 FROM tablename
    UNION SELECT ItemID, 5, Qty5 FROM tablename;

    There is no query builder or wizard for UNION, must type into SQL view of query builder.

    Then use the table or UNION query in an aggregate (GROUP BY) Totals 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
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415

  4. #4
    SamuelOu is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2015
    Posts
    16
    Works perfect. Thanks.

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

Similar Threads

  1. return data for similar fields
    By kwooten in forum Queries
    Replies: 5
    Last Post: 08-06-2013, 02:18 PM
  2. Replies: 1
    Last Post: 06-27-2013, 09:33 AM
  3. Replies: 1
    Last Post: 04-02-2012, 04:20 PM
  4. Return all fields even if lookup is empty
    By skarden in forum Access
    Replies: 2
    Last Post: 05-11-2011, 10:44 AM
  5. Using Caluculated fields to return text
    By InsaneJammer in forum Access
    Replies: 8
    Last Post: 04-08-2011, 07:52 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