Dataset Min/Max Date Expression

I have a dataset on a sparkline populated by a tag history binding. I’ve used min() and max() expressions to get the min and max value. I’d like to do the same to get the start and end date from the dataset, but the same expression isn’t quite working on the t_stamp column.

For instance, max (works):

max({Root Container.Sparkline Chart.data},1)

End date (doesn’t work):

max({Root Container.Sparkline Chart.data},0)

How can I get the start and end date from the sparkline dataset?

You cannot get it from the dataset, as history results don't guarantee that result timestamps fall exactly on the start and end boundary. For any aggregate, the last timestamp will be one interval short of the boundary.

You have to be feeding the history binding a date range, so you should simply use that.

Using realtime, last 8 hours.

It’s just any other dataset at this point with a t_stamp and a value column. There should be a way to get a numeric representation of the t_stamp value and find the min/max, right?

Maybe like this for generic use, but your dataset would already be sorted right?

// sort by date descending, then grab first row value
sortDataset({Root Container.Sparkline Chart.data},0,False)[0][0]
2 Likes

It’s a tag history binding, I believe they are sorted oldest is [0] and newest is [len()-1] so, I guess there’s my answer. Officially:

{dataset}[0,'t_stamp']

and

{dataset}[len({dataset})-1,'t_stamp']

Of course, if it’s any old dataset it would have to be sorted first, tag history already is