PC Review


Reply
Thread Tools Rate Thread

Compare multiple values to select lowest value

 
 
Burnett71
Guest
Posts: n/a
 
      15th Jun 2009
For some reason, I can't figure this out...

I have 3 currency fields in a table with varying amounts. I have a query in
which I need to compare the amounts in these three fields, then select the
lowest value for use in a subsequent calculated field. I'm hoping and
looking for a simple function or module to accomplish this. Any suggestions?
 
Reply With Quote
 
 
 
 
vanderghast
Guest
Posts: n/a
 
      15th Jun 2009
MaxPrice: SWITCH( price1>=price2 AND price1>=price3, price1,
price2>=price3, price2, true, price3)


as computed expression, then, use MaxPrice as required (except in the WHERE
clause, or in the ORDER BY clause). If you need to use that value in the
orderby clause, or in the where clause, save that query and use another
query that will use that saved query.

I assumed your prices are NOT null.


Vanderghast, Access MVP



"Burnett71" <(E-Mail Removed)> wrote in message
news:956799B6-22FB-464B-B434-(E-Mail Removed)...
> For some reason, I can't figure this out...
>
> I have 3 currency fields in a table with varying amounts. I have a query
> in
> which I need to compare the amounts in these three fields, then select the
> lowest value for use in a subsequent calculated field. I'm hoping and
> looking for a simple function or module to accomplish this. Any
> suggestions?


 
Reply With Quote
 
vanderghast
Guest
Posts: n/a
 
      15th Jun 2009
ooops, you wanted the min, not the max....

MinPrice: SWITCH( price1<=price2 AND price1<=price3, price1,
price2<=price3, price2, true, price3)



Vanderghast, Access MVP



"vanderghast" <vanderghast@com> wrote in message
news:0BBB24CC-BDE4-440B-AE09-(E-Mail Removed)...
> MaxPrice: SWITCH( price1>=price2 AND price1>=price3, price1,
> price2>=price3, price2, true, price3)
>
>
> as computed expression, then, use MaxPrice as required (except in the
> WHERE clause, or in the ORDER BY clause). If you need to use that value in
> the orderby clause, or in the where clause, save that query and use
> another query that will use that saved query.
>
> I assumed your prices are NOT null.
>
>
> Vanderghast, Access MVP
>
>
>
> "Burnett71" <(E-Mail Removed)> wrote in message
> news:956799B6-22FB-464B-B434-(E-Mail Removed)...
>> For some reason, I can't figure this out...
>>
>> I have 3 currency fields in a table with varying amounts. I have a query
>> in
>> which I need to compare the amounts in these three fields, then select
>> the
>> lowest value for use in a subsequent calculated field. I'm hoping and
>> looking for a simple function or module to accomplish this. Any
>> suggestions?

>


 
Reply With Quote
 
Burnett71
Guest
Posts: n/a
 
      15th Jun 2009
Thank you for your response. Definitely gave me what I needed to finish this
job out.

"JimBurke via AccessMonster.com" wrote:

> I don't know of a Min function in VBA - if there is one you would just use
> that, e.g. create a new field using something like:
>
> MinValue: Min(Cur1,Cur2,Cur3)
>
> Assuming there is no Min function, the only way I can think of to do this in
> that same query is to create a new field based on an IIf statement. I'll call
> the field with the minimum value of the three MinValue, and I'll call the
> three currency fields Cur1, Cur2, Cur3. Create a new field in the query like
> this:
>
> MinValue: IIf(Cur1 < Cur2 and Cur1 < Cur3, Cur1, IIf(Cur2 < Cur1 and Cur2 <
> Cur3, Cur2,Cur3))
>
> Pretty sure that should work, assuming all 3 currency fields will always have
> values. If it's possbile some or all 3 currency fields may have null values
> sometimes, then you'd need to decide what you want to do in case of a null
> value. If you wanted to treat a null value as 0 you'd have to replace the
> field name in the comparison using the nz function, e.g. nz(Cur1,0) < nz(Cur2,
> 0), etc. If you don't want to use a null value as a minimum you could use Nz
> and assign a very high number that you know will always be < the other
> numbers, e.g. Nz(Cur1,999999) or something like that.
>
> Burnett71 wrote:
> >For some reason, I can't figure this out...
> >
> >I have 3 currency fields in a table with varying amounts. I have a query in
> >which I need to compare the amounts in these three fields, then select the
> >lowest value for use in a subsequent calculated field. I'm hoping and
> >looking for a simple function or module to accomplish this. Any suggestions?

>
> --
> Jim Burke
>
> Message posted via AccessMonster.com
> http://www.accessmonster.com/Uwe/For...dules/200906/1
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
compare 2 columns and select the lowest Delya Microsoft Excel Misc 2 8th May 2010 07:07 PM
How to select an average of the lowest 10 record values jgeniti Microsoft Access 1 12th Jun 2008 08:40 PM
Comparing Multiple values to get lowest Value frankjh19701 Microsoft Excel Worksheet Functions 0 6th Mar 2007 05:33 PM
How do I compare values of two cells and display the lowest. =?Utf-8?B?c2hlcnJp?= Microsoft Excel Worksheet Functions 2 21st Jun 2006 07:34 PM
Compare lowest and second lowest records =?Utf-8?B?SXJpbmE=?= Microsoft Access Queries 1 7th Apr 2005 07:55 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:37 PM.