spotfirespotfire-analyst

Earlier and Latest date of two columns


I am analyzing some data that has two DateTime columns indicating the date of starting production of different products for a facility. So the data looks like this:

FacilityID, DateStart Product1, DateStart Product2
111, 2022-02-01, 2022-01-15
200, 2019-01-01, 2019-03-01

My result needs to be the earliest of the two dates. The result would show this:

FacilityID, Start Date
111, 2022-01-15
200, 2019-01-01

I may be wrong; but I have not found an out-of-the-box function that can check two dates and give me the earliest (or latest) of the two dates.

Any ideas how to do this?


Solution

  • I came up with this and it works great:

    If(DateDiff('day',[DateStart Product1],[DateStart Product2])<=0,[DateStart Product2],[DateStart Product1])
    

    If that gives me a negative number or zero then I know my Product2 is the earliest. Positive and my Product 1 is the earliest. Hope that helps!