The formula data reference allows you to complete simple calculations which will not be saved to
PI tags. When the time context of PI System Explorer is set to now as is by default the
formulas represent the current value and when used in PI Vision displays, they're calculated for the
end time of the display. They can even be used to create trends in PI Vision. Let's go through a few
simple examples. The first is calculating the difference between our current oil temperature
and our target oil temperature, both of which are attributes that we've already built. In the
second example let's calculate the time since maintenance has been completed on a pump. Lt's
get started on our first example, calculating the difference between two attribute values.
Let's go hop on to PI System Explorer and here we're at line 1 in our inlet pump and
taking a look at our attributes, here's our oil temperature 234 degrees Fahrenheit and we have
a target oil temperature of 201 which is a table lookup based on our pump flow rate and that's an
interpolated value from the table. For our formula calculation we just want to take the difference
between these two values, there's no reason to store it as a PI point to save its history,
so we're going to go ahead and create a new attribute that takes the difference between
these two. We'll go to the library since the pump is made from the pump template and I'm going to
create as a child attribute just for convenience here. Let me do my oil temperature difference and
I'm going to sign it as a data reference type of formula and is value type double. I'll click
settings to configure the formula data reference. On the left pane here we have the parameters,
these are your incoming variables. Let me click the star to define my first one I'll
just choose variable A and that'll be my target oil temperature. It has default units of degrees
Fahrenheit and we want to use Fahrenheit in our calculation. So, I'm just going to explicitly
state Fahrenheit here and let me do the same thing for a new variable B and this will be the
current oil temperature based on the PI point data reference and same thing for the temperature here.
Now I actually want to take the absolute value of the difference and let me create an output
here or one of our equations that outputs a result. And here are some of the shortcuts we
can bring in our variables, various operators, functions and in this case, we're going to use
absolute value which is here and then we have a substitution parameter for the current time which
we're actually going to use in the next example. So for functions let me go ahead and bring in
absolute value and I'm going to do A minus B. Doesn’t it really matter if it's A minus B,
B minus a because we're going to take the absolute value. Now the output of this equation is going
to be in degrees Fahrenheit difference which is slightly different than just degrees Fahrenheit.
So, let's see if we can find that here in the list and here it is Delta degrees Fahrenheit.
I go ahead and click OK and one more thing, we said that the output of the formula data
reference is to Delta degrees Fahrenheit, but we also want to make sure that that's
displayed by our client, and we can do that by clicking here on our default unit of measure,
doing temperature Delta, Delta degrees Fahrenheit. Let's go back to our element and refresh just to
make sure we have the most recent data for both oil temperature and target oil temperature,
and then the calculated difference here is 33 degrees Fahrenheit, as a difference between two
different temperatures. Let's go ahead and work on our second example and this is to calculate the
time since pump maintenance has been completed. If we go back here, we have an attribute called
the last repair date this is actually done as a table lookup and in the table, which I'm going
to take a look at in the library, I just have one simple value here based on the serial number. This
is actually the repair date and time and there is explicitly stated a time zone. So what AF is
going to do is this last repair date is actually going to be in the current time zone of my client
machine. So, if I can take a difference between the current time on my client and this repair
date as consensus time is already corrected for my client, that'll tell me the time since last
repair. Let me go ahead and right-click and again because of the template we're going to have to
go into the library instead. Let me go back to pump template. I'm going to right click
and I'm going to create a new child attribute and I'm going to say days since last repair.
My data reference is again going to be formula and I'll click on settings. The only variable I
need to bring in in this case is going to be the last repair date and there's no unit of measure.
The equation I need is to take the difference between now and the last repair date. So,
the substitution parameter is going to be % time % that's the current time on this client machine,
wherever this is evaluated and remember this isn't actually stored anywhere it's evaluated
locally on each client machine. And then the last repair date. Now I know that this is going to
actually have an output in seconds so I'm going to make sure that I explicitly state that this
is done in seconds. And let me click OK. Now I want my result to actually be in days. So,
for the default unit of measure for what I want to display it as I'm going to say days. So,
because I said the output was in seconds but my default unit of measures is days it's going to
do that conversion for me. And if I go back to elements and here's the last repair date
and if I open this up it's been a hundred and ninety-four days since my last repair.
And again the conversion from seconds to days is done because I explicitly stated that this output
was in seconds because that's the way that this formula works here. And then by putting
days here it does the conversion for me. And we've looked at two different simple
examples for formula data references, where you don't need the history of the calculations
saved and instead it's done locally on your client. The first is calculating
the difference between two attribute values and the second is doing a simple time calculation,
calculating the difference between the current time and the time saved in an attribute.