Results 1 to 3 of 3
  1. #1
    Plasmodicum is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Posts
    2

    Combine certain records when calculating averages


    I have two fields of interest for a query, Field1 and Field2. Field1 is qualitative (text) and it may contain either a 1-digit number, a 2-digit number, a number and a letter, or just a letter. Field2 is quantitative data (integers). I am using the query to find the averages in Field2 as grouped by Field1 (identical Field1 values). However, there are certain groups in Field1 which, for this query, I would like to treat as one group. They all follow a similar, unique format for Field1: "0[A-G]", e.g. 0A, 0C, etc. Ideally, the query would rename/collapse/combine all these as "Unk" and provide their combined Field2 averages (and combined counts).

    Now, for sorting purposes, I have already coerced the single digit numbers in Field1 to 2-digit numbers with the following:

    Expr1: IIf(IsNumeric([Field1]), Format([Field1],"00"), [Field1])

    This allows all numbers to be in numerical order, followed by letters in alphabetical, which is desirable. So, if your solution can work around or with this already in place, that would be excellent.

    This seems like a simple problem, but I am brand new to Access.

  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,644
    Need to calculate a value for this group to use for sorting/grouping by this other rule. What exactly is this rule? All values with a letter A-G? Any letters after G?

    IIf([Field1] Like "*[A-G]*", "Unk", IIf(IsNumeric([Field1]), Format([Field1],"00"), [Field1]))

    or

    IIf(IsNumeric([Field1]), Format([Field1],"00"), "Unk")
    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
    Plasmodicum is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Posts
    2
    June7,

    Nailed it. The nested IIf function worked exactly right. I knew it would seem obvious afterward. Thank you so much.

    Answer: IIf([Field1] Like "0[A-G]", "Unk", IIf(IsNumeric([Field1]), Format([Field1],"00"), [Field1]))

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

Similar Threads

  1. Replies: 7
    Last Post: 11-19-2014, 05:20 PM
  2. Replies: 1
    Last Post: 04-29-2014, 12:20 AM
  3. Combine several records into one record
    By Helge in forum Queries
    Replies: 9
    Last Post: 01-25-2014, 03:26 PM
  4. VBA Loop to Combine Records
    By admessing in forum Queries
    Replies: 23
    Last Post: 03-06-2012, 11:37 AM
  5. Replies: 23
    Last Post: 06-30-2010, 02:05 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