Re: Find Nearest Value
From: Allen Browne (AllenBrowne_at_SeeSig.Invalid)
Date: 09/29/04
- Next message: Luong: "Re: Help Create query for over due calibration?"
- Previous message: Sarah (Sustainable Food Center): "How do I run a query in ACCESS within restricted parameters?"
- In reply to: Tom: "Re: Find Nearest Value"
- Next in thread: Tom: "Re: Find Nearest Value"
- Reply: Tom: "Re: Find Nearest Value"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 30 Sep 2004 01:15:55 +0800
Try entering something like this into the Field row in query design:
([ID] = (SELECT First([ID]) FROM MyTable AS Dupe ORDER BY
Abs(Dupe.[Amount] - 475)))
It may show 0 for false, and -1 for true.
-- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Tom" <anynomys@newsgroup.com> wrote in message news:uP73oNkpEHA.3524@TK2MSFTNGP15.phx.gbl... > Allen, > > thanks for the info... this didn't give me the TRUE/FALSE though. > > Any ideas as to how I can implement it? > > Tom > > > > "Allen Browne" <AllenBrowne@SeeSig.Invalid> wrote in message > news:#AxjgojpEHA.1992@TK2MSFTNGP09.phx.gbl... >> What you are asking for is the minimum absolute difference: >> SELECT First([Amount]) FROM MyTable ORDER BY Abs([Amount] - 475); >> >> You could use that kind of expression in the context of a query as a >> subquery. If you need something in VBA code, DLookup() won't work because > it >> lacks the ORDER BY argument, but this replacement will: >> http://members.iinet.net.au/~allenbrowne/ser-42.html >> >> -- >> Allen Browne - Microsoft MVP. Perth, Western Australia. >> Tips for Access users - http://allenbrowne.com/tips.html >> Reply to group, rather than allenbrowne at mvps dot org. >> >> "Tom" <anynomys@newsgroup.com> wrote in message >> news:eV9B0cjpEHA.1644@tk2msftngp13.phx.gbl... >> >I need some help with finding the "nearest" value and add TRUE/FALSE >> >into >> >an >> > expression field. >> > >> > This is the data as pulled from the query: >> > ========================== >> > >> > ID Amount >> > 1 100 >> > 2 99 >> > 3 510 >> > 4 450 >> > 5 21 >> > 6 1000 >> > 7 375 >> > 9 395 >> > >> > >> > I want to find the "Amount" that is nearest to "475". >> > >> > The "direction" can be either "above" or "below" 475. In this case, > "450" >> > is TRUE (below amount). >> > >> > >> > This is the data as I want to see it when qry is executed: >> > ==================================== >> > >> > ID Amount Expression >> > 1 100 False >> > 2 99 False >> > 3 510 False >> > 4 450 True >> > 5 21 False >> > 6 1000 False >> > 7 375 False >> > 9 395 False >> > >> > If the number to be found was "490", I would expect "510" to be TRUE > (and >> > 450 to be FALSE). >> > >> > >> > Does anyone know how to do that? >> > >> > >> > Thanks, >> > Tom >> > >> > P.S. As shown above, the records are sorted by ID
- Next message: Luong: "Re: Help Create query for over due calibration?"
- Previous message: Sarah (Sustainable Food Center): "How do I run a query in ACCESS within restricted parameters?"
- In reply to: Tom: "Re: Find Nearest Value"
- Next in thread: Tom: "Re: Find Nearest Value"
- Reply: Tom: "Re: Find Nearest Value"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|