Trying to find a way to retrieve the last unique/different value in AF. I don't want the last recorded value if it is the same numeric value as it is currently.
You can do this by using a filter such as "PrevVal('.', '*') <> '.'" to filter out unique values to another attribute. The current value of that attribute will then be the last unique value. This is for Asset Analytics.
For AF SDK, it is more straightforward as below. The highlighted row in blue is the one we are trying to find. The sample code achieves that.
var vals = attr.Data.RecordedValues(new AFTimeRange("*-1y", "*"), AFBoundaryType.Inside, null, " PrevVal('.', '*') <> '.' ", false); Console.WriteLine("Last unique value:" + vals.Last().Value + "\tTimestamp:" + vals.Last().Timestamp.ToString());
Ah! I had stepped around this solution but never got the syntax quite right. Thanks so much!
Eugene's answer will work out nicely. Out of curiosity why can't you use compression filtering to avoid duplicate values in your PI Points?
Yeah, I think this will be the better solution in the long run. I thought of this later, and found the compression to be off for these few tags. So I turned it back on.
Retrieving data ...