Results 1 to 3 of 3
  1. #1
    skydivetom is online now VIP
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    1,046

    Need assistance with Query Expression that pulls values from lowest populated tier level

    Hello:



    I need assistance with developing a query that checks up to 5 fields and only outputs a value from the lowest tier level (T5 up to T1).

    Background:
    - I have a table that contains 5 fields: [TIER1] through [TIER5].
    - Not all of the 5-tiered fields are populated. That is, sometimes I may have a value in tier 1 (aka T1), no value in T2, but then a value in T3.
    - Going form the *lowest* (T5) to the *highest* (T1) tier level -- aka right to left -- I want my expression to pick up the value on the *lowest* level (starting with T5).
    - In this case, I have manually highlighted (in yellow) the values that I want the expression to pick up.

    Example #1 (where ID = 1):
    - T1 = 113; T2 and T3 are null, T4 = 498, T5 = null.
    - Business rule for expression: Given T5 = null, I check T4. In this case, T4 <> null. Hence, I output "498".

    Example #2 (where ID = 9):
    - Business rule for expression: T5 = null, T4 = null, T3 = 312. Hence, I output "312".

    I added the following expression to my query.
    Code:
    Expr: IIf(IsNull([TIER5]),[TIER4],IIf(IsNull([TIER4]),[TIER3],IIf(IsNull([TIER3]),[TIER2],IIf(IsNull([TIER2]),[TIER1],[TIER5]))))
    Unfortunately, as illustrated in the JPG, the results are incorrect. With the exception of 4 (out of 15), I get only null values.
    And for those 4 records (ID 1, 5, 6, 476) where I do display values, record # 6 is incorrect. It shows "165" when it should have been "562".

    My question: How do I need to rewrite the expression so that I get the output that is displayed in JPG (cell range G2:G16)?

    Thank you,
    EEH
    Attached Thumbnails Attached Thumbnails Summary.jpg  
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    SELECT *, Nz(Tier5, Nz(Tier4, Nz(Tier3, Nz(Tier2, Tier1)))) AS T FROM table;
    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
    skydivetom is online now VIP
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    1,046
    June7... thank you!! That's the perfect solution. I appreciate your assistance.

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

Similar Threads

  1. Replies: 5
    Last Post: 08-08-2019, 11:10 AM
  2. Replies: 4
    Last Post: 04-04-2018, 09:14 AM
  3. Replies: 11
    Last Post: 04-11-2014, 04:26 PM
  4. Replies: 2
    Last Post: 02-20-2014, 05:54 PM
  5. Using expression builder to find lowest date
    By MMcKenna in forum Queries
    Replies: 1
    Last Post: 03-20-2012, 02:28 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