Comparing Tag Values Senior Moment

I seem to always make simple this more complicated that they should be. I have two tags. The first tag runs a query that gits the number if event over the last minute (represents a feed rate). The second tag stores the fastest rate achieved during a shift.

When the first tag value is greater than the second tag, the faster rate is stored in the second tag, if the current rate is slower than the maximum, the second tag is not changed.

DD_231_current (the first tag) working query is:

SELECT COUNT(DD_231) FROM dockDoorInducts
WHERE currentTime > DATE_ADD(NOW(), INTERVAL -1 MINUTE);

DD_231_Peak (the second tag) nonworking expression is:

if (({[.]DD_231_Current} >= {[.]DD_231_Peak}), {[.]DD_231_Current}, {[.]DD_231_Peak})

I have tried various combinations of parentheses and groupings. The errors I get are :
“if function got a null first argument” and “Error Configuration”

I am using 8.0.12

if(
	{[.]DD_231_Current} >= {[.]DD_231_Peak},
	{[.]DD_231_Current},
	{[.]DD_231_Peak}
)

Looks like the logic is correct, but I’m guessing the comparison operator is failing because the tags are briefly null during tag initialization. You could try wrapping it all in a try; change the 1 to 0 if you want to default to using Peak instead of Current:

if(
	try({[.]DD_231_Current} >= {[.]DD_231_Peak}, 1),
	{[.]DD_231_Current},
	{[.]DD_231_Peak}
)
1 Like