I am trying to use PI to calculate inventory of a product we make. The product inventory is not stored in any system. We know how much is made per day and how much we sold per day but not sure how to get the inventory into a tag. We currently use analysis in AF to calc the amount produced for yesterday and the same for amount sold. I know inventory is (Yesterdays inv amount + amount produced) - amount sold and I have this in analysis but how do I write this to a tag but keep the yesterday inv amount to use in the next days calculation?

Let's assume there are 3 tags:

Yesterdays inv amount, amount produced and amount sold

Since you already have your formula for the end of day/period inventory:

(Yesterdays inv amount + amount produced) - amount sold

and you have calculations for amount produced and amount sold, the missing piece seems to be the BEGINNING inventory that is used to seed the rest of the calculations.

So, create the tags and the analysis and then manually seed the starting value for 'Yesterdays inv amount'; how you determine that value is dependent on your processes.

Then, your end-of-day inventory that will become the new value for 'Yesterdays inv amount' will be:

TagVal('Yesterdays inv amount','*-1d) + 'Amount Produced' - 'Amount Sold'

that value will be written to the scheduled time.

And that value will be used the next day... moving forward.