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

**URL:** <https://forum.inductiveautomation.com/t/how-to-make-conditions-on-a-max-value-analog-tag-for-reporting/112141>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [November 12, 2025, 9:58pm UTC](https://forum.inductiveautomation.com/t/how-to-make-conditions-on-a-max-value-analog-tag-for-reporting/112141 "2025-11-12T21:58:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jyonke](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@jyonke](https://forum.inductiveautomation.com/u/jyonke)\
**Post date:** [November 12, 2025, 9:58pm UTC](https://forum.inductiveautomation.com/t/how-to-make-conditions-on-a-max-value-analog-tag-for-reporting/112141/1 "2025-11-12T21:58:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [November 12, 2025, 10:06pm UTC](https://forum.inductiveautomation.com/t/how-to-make-conditions-on-a-max-value-analog-tag-for-reporting/112141/2 "2025-11-12T22:06:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [November 13, 2025, 4:06pm UTC](https://forum.inductiveautomation.com/t/how-to-make-conditions-on-a-max-value-analog-tag-for-reporting/112141/3 "2025-11-13T16:06:50Z")

</div>

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:

```python
#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.

---

<div class="post-metadata">

**Author:** ![drojas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drojas/32/3403_2.png) [@drojas](https://forum.inductiveautomation.com/u/drojas)\
**Post date:** [November 13, 2025, 5:26pm UTC](https://forum.inductiveautomation.com/t/how-to-make-conditions-on-a-max-value-analog-tag-for-reporting/112141/4 "2025-11-13T17:26:39Z")

</div>

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.

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

```

---

<div class="post-metadata">

**Author:** ![jyonke](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@jyonke](https://forum.inductiveautomation.com/u/jyonke)\
**Post date:** [November 13, 2025, 6:00pm UTC](https://forum.inductiveautomation.com/t/how-to-make-conditions-on-a-max-value-analog-tag-for-reporting/112141/5 "2025-11-13T18:00:55Z")

</div>

What is 410 representing

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [November 13, 2025, 6:09pm UTC](https://forum.inductiveautomation.com/t/how-to-make-conditions-on-a-max-value-analog-tag-for-reporting/112141/6 "2025-11-13T18:09:39Z")

</div>

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

> **[Quality Codes and Overlays | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/platform/tags/quality-codes-and-overlays#quality-code-reference-table)**
>
> A Quality Code represents a level of confidence in a value. Quality codes are made up of a level (Good, Bad, Error, or Uncertain) and an integer. If a value's quality is not Good, the value generally should not be trusted.

---

<div class="post-metadata">

**Author:** ![drojas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drojas/32/3403_2.png) [@drojas](https://forum.inductiveautomation.com/u/drojas)\
**Post date:** [November 13, 2025, 8:24pm UTC](https://forum.inductiveautomation.com/t/how-to-make-conditions-on-a-max-value-analog-tag-for-reporting/112141/7 "2025-11-13T20:24:05Z")

</div>

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