You are here

Retrieving the first value of a variable timeseries

I have a variable X which I need to set to a fixed value equal to the first value from a timeseries Y. The timeseries Y changes every time I run the model and is of variable length so I need to be able to set the variable X on the fly (since the model is completely automated).

I'm able to get the last value using the last() function but am not able to retrieve the first value of timeseries Y and set X to that constant value. The first() function is not comparable and the if() function requires that an else() be attached which doesn't help me since I want the X variable to equal the first value from timeseries Y at every timestep in the run.

If I try to retrieve an element() from the timeseries vector it fails because it is a variable rather than a fixed array.

Any suggestions?

Forums: 

The prev() function used with if will do the job:
x=if time()==0 then y else prev(1)
.