2 of 2 people found this helpful
How about using AF Table Link?
Using PI OLEDB Provider, syntax like this.
SELECT TOP 10 time, cast(value as float32)
WHERE tag = 'sinusoid'
AND time BETWEEN '*-1y' AND '*'
ORDER BY time DESC
I used cast because of KB.
KB00852 - PI AF Unable to link to external table: Unexpected Server Error: Invalid name character
Now I could get 10 events.
After that, Attribute should be Table Look up.
Rule = Table provided time series data.
Now I could get only 10 events by PI ProcessBook.
Does it work for you?
If you want to add a bit of code to your Processbook, you could do this very easily with the PISDK, use the built in recorded values by count function, then set the start and end time of your trend to the timestamps of the first and last value you find.
I did this, added a combo box and populated it with some values like 25,50,75,100,150,200,250,500
Then added this handler to the on change, this is simplified straight line code but should get you on the right track. (Be sure to add PI-SDK 1.3 Type Library to your VBAProject)
It's always starting at *, so I use dReverse option to go backwards in the archive, for this reason the start time is the last value in pivals (which will be index num) and the end is the first value (index 1).
Private Sub ComboBox1_Change() Dim pisrv As PISDK.Server Dim pipt As PIPoint Dim pivals As PIValues Dim pival As PIValue Tag = Trend1.GetTagName(1) Server = Mid(Tag, 3, InStrRev(Tag, "\") - 3) TagName = Mid(Tag, InStrRev(Tag, "\") + 1, Len(Tag)) num = ComboBox1.Value Set pisrv = PISDK.Servers(Server) Set pipt = pisrv.PIPoints(TagName) Set pivals = pipt.Data.RecordedValuesByCount("*", num, dReverse, btAuto) Trend1.SetStartAndEndTime pivals(num).TimeStamp.LocalDate, pivals(1).TimeStamp.LocalDate Set pivals = Nothing Set pipt = Nothing Set pisrv = Nothing End Sub
TrendByCount.pdi.zip 9.0 KB