Need for Minimum function

G

Guy

I have to find the minimum of different values, but no
aggregate!

e.g. : Minimum of ( Table1.Cost1 , Table2.Cost1 , Table3,
Cost1 )

Thank you very much for helping me out.
 
A

Allen Browne

The best solution would be to change the data structure to a normalized one,
where you don't have to search across multiple fields or tables.

However, this function will return the lowest numeric value from a list
passed in. For example, if you have Table1, Table2, and Table3 in a query,
you could enter a calcualted field into the query grid (Field row) like
this:
MinCost: Minimum(Table1.Cost1, Table2.Cost1, Table3.Cost1 )

Function Minimum(ParamArray varValues()) As Variant
Dim i As Integer 'Loop controller.
Dim varMax As Variant 'Lowest value found so far.

varMax = Null 'Initialize to null

For i = LBound(varValues) To UBound(varValues)
If IsNumeric(varValues(i)) Then
If varMax <= varValues(i) Then
'do nothing
Else
varMax = varValues(i)
End If
End If
Next

Minimum = varMax

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top