4 Replies Latest reply on May 23, 2017 3:02 PM by tmcmanus

    Is there a PrevVal equivalent in the formula DR?


      I am trying to use the Formula Data Reference to perform simple calculations, where the input variables are Table Lookup Data References that are configured to return time series data. My use case for this is to perform simple calculations on data with future timestamps. So far this has worked out well for me, and the output attribute returns a time series with future data as expected (when I request time ranges that extend into the future).


      Now I want to include another input variable that refers to a PI Point Data Reference. The issue I am facing is that I want the Formula DR to only evaluate the most recent archived value for the PI Point DR, even when evaluating the Formula DR expression at future times. Essentially, I am trying to use the PrevVal function in the Formula DR, but this does not seem to be available.


      Is there a solution that makes this possible? I have tried numerous things, including:


      • Setting the value retrieval method for the PI Point DR to "Before" or "At or Before"
      • Using an AF Analysis to output the result of PrevVal('Tag', '*') to an output attribute
      • Routing the value of the PI Point DR to another attribute configured using the String Builder DR


      However, none of these seem to be working. When the Formula DR evaluates this input at future timestamps, it gets back "No Data," which causes the entire Formula DR to fail. The only way I have found to prevent the Formula DR from failing is to use a BadVal check on the input variable and return a fixed default value, but this is not a viable solution for my particular use case.


      Interested to hear your thoughts on this problem.

        • Re: Is there a PrevVal equivalent in the formula DR?
          John Messinger

          The Formula DR is intended to be used for standard math functions, and has extremely limited support for PI specific functions (only badval and digstate). Archive functions such as PrevVal, PrevEvent etc aren't supported by this data reference. If the options you listed and have tried so far aren't giving you the intended results, I would consider moving the entire calculation to an Expression Analysis where the required archive functions are natively supported, and you can wrap the entire logic and functionality of your calculation in a single configuration location. Otherwise you may end up spending a lot of time trying to find a second rate workaround with the Formula DR.

          2 of 2 people found this helpful
            • Re: Is there a PrevVal equivalent in the formula DR?

              Thanks John, that's kind of what I figured about the Formula DR. I tried implementing my use case with Expression Analysis, but it seems to be more cumbersome than using the Formula DR to be honest. The problem I have with Expression Analysis is that for future data, the output is written only for a single time point. If I have multiple future time points I need to output, the analysis becomes very large and unmanageable. Using the Formula DR works better because it evaluates for every time point I request, so it "just works" with all client tools (as well as the PI Web API). Although I do agree with you that the Formula DR is limited in what calculations it can perform.


              I did actually find a workaround though, albeit a clumsy one, for what I'm trying to accomplish. If I set up an AFTable that has a single field with a timestamp far in the future (say 12/31/9999 11:59:59 PM), then I can set up a Table Lookup DR on that table. The TLDR has to be configured to return a time-series data, and will return the value of some other attribute (which can be a PI Point DR) when no matching row is found. This effectively makes an attribute whose value is the latest archived value of some tag no matter which time is requested.

                • Re: Is there a PrevVal equivalent in the formula DR?
                  John Messinger

                  Yes, I agree that in this case for multiple time point outputs the Expression Analysis also has it's limitations. This is where Formula DR would have an advantage as you indicated. Glad you found a solution ("hacks" are often what we do, right?).


                  This is the interesting thing I've found with PI over the years - no matter what kind of use cases the developers anticipate for the software, seems we users can always find plenty of uses (edge cases perhaps) that either just never were identified, or were considered too far on the edge. Or, our business needs are just ever expanding requiring new ways to solve problems

                  • Re: Is there a PrevVal equivalent in the formula DR?

                    Very interesting workaround Aaron. Does it accomplish what you were looking for?


                    As John says, we are always trying to continue developing features our users want and need, but our user base tends to come up with very creative uses for our system that we sometimes didn't realize was a need!


                    If you'd be willing to provide us insight and feedback into the use-case and goal you were working towards, it'd be a great addition to our Feedback Engine, where customers and employees can vote on topics, and our PMs review all of them. PI Server: Analytics & Calculations (70 ideas) – Customer Feedback for OSIsoft & the PI System