I am not sure what your question is at the moment. To me, it looks like your syntax in your last statement is correct. I tested this by hardcoding the variables you have in your statement and everything evaluated like I would expect.
IF (timedelta1 < 5) THEN (val1) ELSE (IF (timedelta2 < 5) THEN (val2) ELSE (val3))
I'm not sure why it didn't work for me either. It kept saying that the closing parenthesis was a syntax error. When I wrote per Gabriel's response without parentheses and on separate lines, all worked.
Unfortunately there is no function that does what you want and the only solution I can imagine is using Analysis like you have done, however I would have done it a bit differently:
time1 = PrevEvent('.\Child|attr',time)
time2 = PrevEvent('.\Child|attr',time)
time3 = PrevEvent('.\Child|attr',time)
val1 = PrevVal('.\Child|attr',time)
val2 = PrevVal('.\Child|attr',time)
val3 = PrevVal('.\Child|attr',time)
MaxTS = Max(time1,time2,time3) // Returns the latest time stamp
For the last part you would need to found out which timestamp is the greatest and output the correspondent attribute value:
IF MaxTS = time1 THEN val1 ELSE
IF MaxTS = time2 THEN val2 ELSE val3
// IF MaxTS = time3 THEN val3 ELSE
I hope any of this helps!
I'm not entirely sure what was wrong with mine, but extending this worked great! Thank you for your help.
Are the child element attributes PI Points?
Yes they are all child elements built from a single template.