How to make Conditions on a Max Value analog tag for reporting

I am reporting a Max daily value of OPC analog tag. I would like to know how to report the max value of this tag only when it is operating not in backwash mode.

How are you determining when the tag is in backwash mode? Is there an additional tag that shows the state?

You could run a Gateway tag change event that will check the mode and see if the latest value is higher than the current stored 'highest' value. If the new value is higher, overwrite the stored value.

If you are trying to report this off historical data, then you'll need to write a script to determine 'windows' of time in the historical data to omit from the dataset based off the recorded mode. After removing said windows of time, you can utilize system.math.max to give you the largest value.

Sounds like a job for the PLC. Ideally your PLC time and gateway time are synced and you’re not relying on the gateway to log the change or reset the max value (I do this on a daily basis with a gateway script). Then you can use 4 tags and just do it in the PLC.

I would use 3 tags. in_backwash status tag (INT/BOOL), value tag (REAL), max_value tag (REAL).

Pseudocode:

#new max value
if value > max_value:

    #not in backwash, store new max
	if not in_backwash:
		max_value = value


#reset at 0000
if time_DINT == 0000:
	max_value = 0
     

Turn on history for max_value

If you’re using the reporting module I don’t think you need to script at all. You can select max as the aggregation mode on the history query.

1 Like

If you want to historize the max value tag only when in production (or whatever state you need), you might consider creating an expression tag that checks if you are in the production mode you need, then show the value, otherwise force the quality of the tag to 410. Enable history on this tag and your graph will show broken lines of just the max value and not drop down to 0 when not in the state.

if({[.]StatusTag},{[.]MaxValueTag}, forceQuality(None,410))

What is 410 representing

Based on the reference tables, looks like a quality code for uncertain.

Yes, Uncertain is one of the quality values that generates a gap in the graph.