Sure is, the key is to use an expression instead of the tag directly.
In Datalink you can use Advanced Calculated Data and use an expression. Something like:
'YouPITag' = "YourDigState" and PrevVal('YourPITag','*') <> "YouDigState"
Ensures that your duplicate events in the archive are ignored unless there was a change to the value to be come your digital state of interest.
Set your time range, set you mode to Total and Event Weighted.
One gotcha - if you have an error state in between a constant period for the digital state then it would count as 2 occurrences instead of one. You'd have to expand the expression to cover those scenarios.
Wow thanks a lot, that certainly works but my result is one event higher than what actually happened
This is my expression;
=PIAdvCalcExpVal("'GLGP01_GEN.SWG_CBX01_sClosed' = ""FALSE"" and PrevVal('GLGP01_GEN.SWG_CBX01_sClosed','*') <> ""FALSE""","1/09/2013","*","total","event-weighted","compressed","10m",0,1,0,)
When I trend this in PB, I can see 15 False states including the state it was in at the start of the time range but my result in DataLink is 16. Do you know why this is happening?
You must normally have one less than what you expect because it doesn't count the false at the start. After that, you need to adjust.
To be sure of your count, use the Compressed data in Excel to retrieve your events and make the calc manually (used also a shorter period, just to have few events).
Please send us what you have.
Moreover, some tips!!!
Try to put all parameters outside the formula and just refer to the cells (ex: put the ST and ET in dedicated cells, the expression in another cell...) . This is better and easier for maintenance (you are also able to expand the same function to an array and you don't need to "enter" in the formula to make a change). Hope this will help you
Furthermore, check also that you do not have "bad data" in your period.
This could be also the cause. As mentioned by Rhys, this will eb count as a change.
Using compressed data, you will be able to see this easily.
Thanks for the reply Gael. As both you and Rhys suggested, I had a 'Bad Data' Archive entry. Once I deleted this the result came back perfect.
Thanks for the suggestion for using the formulas and reference a cell for the tags and time ranges. This was my plan but I wanted to make sure the calculation worked first.