Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dlookup using nearest value (vlookup true)

Status
Not open for further replies.

jameshopper

Technical User
Jun 2, 2005
11
0
0
GB
Hi,
I have worked on and searched long and hard to come up with a solution to the vlookup(true) Excel function in Access. May of the solutions I have found meant using several queries/subqueries to get to the right results. Luckily, I stumbled across this while looking through the built in functions and thought it would be worth a go. Blow me, it worked. I don't think this easy solution has yet been posted. If it has, I apologize.

Table 1 (lookup table)
Score Band
0 Does not meet
0.97 Meets
0.99 Exceeds
0.975 Minimum Performance

Table 2 (actual data table)
Score Name
0.98 James
0.96 Fred
0.99 Corinne
0.996 Thomas

SQL Code
SELECT Table2.Score, Table2.Name, DMax("[Score]","Table1","[Score] <=" & [Score]) AS Score_Band, DLookUp("[Band]","Table1","[Score] = " & DMax("[Score]","Table1","[Score] <=" & [Score])) AS Band_Description
FROM Table2;


Gave results:
Score Name Score_Band Band_Description
0.98 James 0.975 Middle
0.96 Fred 0 DNM
0.99 Corinne 0.99 Exceeds
0.996 Thomas 0.99 Exceeds

Granted, It's only a small data set to test, but I think it seems to do the trick. Let me know if there are any obvious errors.

James

 
I changed one of the bands descriptions during writing this, which is why one says middle and the other says minimum performance.

James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top