YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Determine number of state changes in a period Options · View
jc113883
#1 Posted : Wednesday, December 02, 2009 1:11:11 AM
Rank: Member
Groups: Member

Joined: 10/7/2009
Posts: 14
Is there a way to determine the number of state changes for a digital tag in a time period?

For example, my valve has two states: Open or Closed. I want to know how many times my valve has opened and closed in the past week.

The intent is for this to be a formula for use in excel.
Sponsor  
 

OSIsoft vCampus is a subscription-based, online offering that consists of providing everything people need to develop applications on the PI System.
We invite you to take a "tour" of the OSIsoft Virtual Campus - also feel free to consult the FAQ  or contact OSIsoft vCampus for more details.
MacaroniPI
#2 Posted : Wednesday, December 02, 2009 2:13:39 PM
Rank: Advanced Member
Groups: Member

Joined: 7/16/2008
Posts: 35
Location: UK
How many tags are we looking at? If its just a few then I would indeed use Excel formulas and make something very simple, its not elegant but you should be able to get it going in about 5 minutes.

Create a sheet like the below.....

Create another sheet like the below.....

Use compressed data function in datalink and reference the cells in sheet1 for start date end date tag name, keep a free column between each tag...in the free column we want a formula that compares the current value with the previous value and determines whether its a state change.


=IF(AND(B4="Closed",B3="Open"),"Closed",IF(AND(B4="Open",B3="Closed"),"Open",""))

Copy that all the way down and repeat it for all the other tags in the relevant columns (F, I, L etc)

Now on the sheet 1 in the Times opened and Times close cells use a count formula

Times opened: =COUNTIF(Sheet2!C3:C31,"Open")

Times closed: =COUNTIF(Sheet2!C3:C31,"Closed")

Each time you update the start and end date the datalink functions should update, in turn updating the formulas and the main page. Simples.

Of course this isn't very scalable, and if you want to do this for 1000s of tags you should probably look to write something in SDK that effectively does the above but in an array and outputs the results. This is how I would (and have) done it, but theres probably better ways...
Who ate all the PIs?
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.