Asatoma Sadgamaya
asked on
Latest date out of 3 date columns
Hi
I have 3 columns with dates on MS Access query. I need find out latest date out of these 3 on my new column.
Please let me know.
Thank you
A
I have 3 columns with dates on MS Access query. I need find out latest date out of these 3 on my new column.
Please let me know.
Thank you
A
ASKER
Thanks for your reply Gustav,
I could see your formula does not work if one value is null I am afraid. It returns null.
Ta
A
I could see your formula does not work if one value is null I am afraid. It returns null.
Ta
A
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
For what it's worth, I only got a NULL as the result of that calculated column if all three columns were NULL. If just one or two were it still returned the largest date of the others. Based on that you might be able to just do:
»bp
LatestDate: Nz(IIf([Date1] > [Date2] And [Date1] > [Date3], [Date1], IIf([Date2] > [Date3], [Date2], [Date3])),0)
»bp
ASKER
Thank you Bill, that worked for me.
Great, glad that helped.
»bp
»bp
ASKER
Bill, what is the difference between your 1st and 2nd formulas. I did not see the 2nd one, I just spotted now.
Can I still use 1st?
Thank you
A
Can I still use 1st?
Thank you
A
Try them both, if they both solve your problem for all cases where NULL shows up then I'd go with the second, it's a bit more efficient.
»bp
»bp
ASKER
Thanks Bill
I use a function, which looks like:
LatestDAte: fnMax([Date1], [Date2], [Date3])
It accepts a parameter array, so you can pass as few or as many values or fields into it as you want.
You can use it with dates, numbers, even strings to find the maximum, although I've never used it with strings.
Public Function fnMax(ParamArray ValList() As Variant) As Variant
Dim intLoop As Integer
Dim myVal As Variant
For intLoop = LBound(ValList) To UBound(ValList)
If Not IsNull(ValList(intLoop)) Then
If IsEmpty(myVal) Then
myVal = ValList(intLoop)
ElseIf ValList(intLoop) > myVal Then
myVal = ValList(intLoop)
End If
End If
Next
fnMax = myVal
End Function
With this function, you would simply write:LatestDAte: fnMax([Date1], [Date2], [Date3])
It accepts a parameter array, so you can pass as few or as many values or fields into it as you want.
You can use it with dates, numbers, even strings to find the maximum, although I've never used it with strings.
your formula does not work if one value is null
That you didn't mention.
That is why I use the function, it ignores NULL values passed to it.
Open in new window