2 Replies Latest reply on Jan 11, 2018 7:07 PM by knightk

    Creating trends based on count, not time


      I want to create a trend that is based on the previous 25, 50, 100, 200 etc. data entries. So far I've only been able to create trends with the independent variable being time. Ultimately I want to be able to specify a certain number (25, 50, 100, 200 etc.) and a trend will appear with the most recent data values, counting backwards from time ' * '


      Is there a pie calc for this? Can i do it using PI AF?

      I'm using the latest version of Pi ProcessBook.


      Any help will be greatly appreciated. Thanks in advance.

        • Re: Creating trends based on count, not time
          Kenji Hashimoto

          How about using AF Table Link?

          Using PI OLEDB Provider,  syntax like this.

          SELECT TOP 10 time, cast(value as float32)

          FROM [piarchive]..[picomp2]

          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?

          2 of 2 people found this helpful
          • Re: Creating trends based on count, not time

            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