IMD SolutionComputing LibraryShop main store

Comparison

Hourly error count from tag history: three ways to persist it

Edge computing and IIoT Published 6 min read By IMD Solution engineering team

Short answer

Count rising edges, assign each to a start-inclusive and end-exclusive hour, and store the events. Discrete tag history with a raw query and script post-processing works when the error Booleans are already historized; a gateway tag-change script writing to an event table fits when you need one record per activation for shared reports.

On this page
  1. Why does the label revert to its default when the hour changes?
  2. What exactly is one error occurrence?
  3. Which storage path fits your lines?
  4. How do array tags map to the displayed errors?
  5. How do discrete history records become hourly counts?
  6. How does the gateway tag-change script path work?
  7. What does the hourly SQL query look like?
  8. How do you verify the count end to end?
  9. Which approach should you build?
  10. Questions asked

The Perspective labels must show the number of false-to-true error transitions in each hour, and that number must survive the hour rollover. The fix is to count stored rising edges and bind each label to a fixed hourly interval, never to an expression driven by the current hour. Two storage paths work: discrete tag history with a script binding, or a gateway tag-change script writing one row per activation to a database event table.

Why does the label revert to its default when the hour changes? #

A time-dependent expression selects values using the current hour, so when the clock advances it selects a different interval and the label falls back to its default. For the 06:00 to 07:00 interval you want nine activations of error 1 and six of error 2 to stay on screen after 07:00; that requires a fixed interval key and stored events, not a live selection. The label binding must ask for a stable period, for example 06:00:00 inclusive to 07:00:00 exclusive, and look its result up in that fixed data.

A Perspective tag binding reads a live tag value, and a tag history binding pulls stored history into the component; the raw history path is the one that returns recorded samples you can post-process. The Ignition manual documents both binding types on the Perspective pages for tag bindings and tag history bindings (https://www.docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/working-with-perspective-components/bindings-in-perspective/tag-history-bindings-in-perspective).

What exactly is one error occurrence? #

One occurrence is the transition from false to true. A Boolean that stays true is one active error, not a new occurrence every time a script or query runs. The true-to-false transition ends the condition and adds nothing. Test the counting rule by holding an error true: a correct implementation adds one count at activation and none while it stays true.

Define the interval as start-inclusive and end-exclusive: an event timestamped exactly 07:00:00 belongs to the 07:00-08:00 bucket, not 06:00-07:00. Apply the same boundary rule in the historian query and in any SQL grouping so both paths produce identical totals.

Which storage path fits your lines? #

Approach Where it lives When to choose it
Discrete tag history plus script History enabled on each error Boolean; raw history query post-processed in a script binding The Booleans already have reliable discrete records and you only need hourly counts; no extra table
Gateway tag-change event logging Gateway event script and a database event table You need explicit event identity, shared SQL reports, and one record per activation across lines
Current-hour expression alone Perspective property or label binding Never for retained totals; it selects current values and reverts at the rollover

Prefer history when the individual Booleans are already historized in discrete mode and only the display needs the counts. Prefer the event table when the reporting design needs explicit occurrences, common database queries, or a centralized mapping across dissimilar lines. A transaction group is not required simply because the output is hourly: the storage trigger follows the error transition, and the hourly query groups the records afterward. If you are still deciding whether an event store or a historian is the right architecture at all, the choice between a historian and an OPC tag server is covered in article:do-you-need-a-historian-or-just-an-opc-tag-server.

How do array tags map to the displayed errors? #

Many lines expose errors as an integer array and a Boolean array, for example 48 elements each, with a spreadsheet symbol list naming each index. Array lengths and signal counts differ between lines, so an index alone is not a stable error identity. Before configuring storage, record for each displayed error the line, the Boolean array element, and its meaning from the symbol list, and verify the actual array length on that line. Then give the reporting layer an explicit error number and line identity, separate from the physical index, so the shared event table stays consistent.

How do discrete history records become hourly counts? #

Configure each error Boolean for discrete history, request raw records for the reporting period, and count rising edges in a script binding. A numeric sum of the stored samples measures true samples, and a duration calculation measures time active; neither is an occurrence count. For each error, read the last valid state immediately before the period start, walk the raw records in timestamp order, and add one occurrence only when a valid false changes to a valid true.

The preceding state prevents a boundary mistake. If an error went true before 06:00 and is already true in the first record of the query, that first true value is not a new 06:00-07:00 occurrence. A false-to-true transition timestamped exactly 06:00:00 does belong to that hour. After a quality gap, a true value with no known preceding state does not establish when activation happened; count that interval as unknown rather than guessing.

Check the counting rule with real data before trusting the labels: for the example period, one rising edge at 06:12 and one at 06:47 for error 1, plus three more elsewhere in the hour, must yield nine for that interval, and the same count must still display after 07:00.

How does the gateway tag-change script path work? #

Configure a gateway tag-change event script on the error Boolean tags. On each change to true, the script writes one row to an event table with the tag path, a mapped error number, the line identity and the timestamp. Because the record is written at activation, every consumer, screens and SQL reports alike, reads the same explicit occurrence, and lines with different array lengths still share one storage format. This is the same pattern used to capture per-station events across multiple assembly lines, and it pairs naturally with the event-logging technique described in article:event-logging-in-ignition-edge-with-one-delimited-string-tag when you need compact event text rather than one row per attribute.

What does the hourly SQL query look like? #

Group the event rows by the hour of the timestamp and sum one per error number. With start-inclusive, end-exclusive bounds in the WHERE clause, an event at exactly 07:00:00 lands in the next bucket automatically:

SELECT dateformat(t_stamp, 'HH:00') AS hour_bucket,
       SUM(CASE WHEN errorNum = '1' THEN 1 ELSE 0 END) AS error1,
       SUM(CASE WHEN errorNum = '2' THEN 1 ELSE 0 ELSE 0 END) AS error2
FROM error_table
WHERE t_stamp >= '2024-03-05 06:00:00'
  AND t_stamp <  '2024-03-05 07:00:00'
GROUP BY hour_bucket
ORDER BY hour_bucket

Read the labels from this fixed result, not from a live calculation. In Perspective, a custom property holds the query result and each label uses a lookup() expression keyed on the hour and the error number, so the displayed nine and six stay put after the rollover.

How do you verify the count end to end? #

Force a known activation on one mapped error and confirm the live tag changed, the storage layer recorded it once, and the hourly total increased by exactly one. Then hold the error true and confirm the count does not move. Finally, roll past the hour boundary and confirm the previous hour keeps its value on screen. For the example hour, the display must show nine and six at 06:55 and still show nine and six at 07:05. If the historian path is involved and stored counts look right but records seem missing, check the completeness of what was actually written before blaming the query, as covered in article:when-store-and-forward-buffered-data-is-stored-in-the-historian.

Which approach should you build? #

If the error Booleans already have reliable discrete history and the only consumer is the hourly display, use the historian path: discrete history, raw query, script-side rising-edge counting with the preceding-state check. If you need explicit event records for shared reports, one row per activation across lines with different array lengths, or a single database source for several screens, use the gateway tag-change script writing to an event table. In both, count only false-to-true transitions, use start-inclusive and end-exclusive hour boundaries, and never let the label depend on which hour is current.

Questions asked

An error activated and cleared between OPC scans. Can the hourly count still include it?

No. Neither tag-change scripts nor history records can reconstruct a transition that the acquisition never observed, because the tag never changed while anyone was watching. If such short events matter, have the controller hold the indication until it is acknowledged, or maintain the occurrence counter inside the PLC where every activation is seen.

Do I need a transaction group to get hourly error counts?

No. A transaction group is a scheduled or triggered write of tag values into a database table; it does not count occurrences by itself. The hourly number comes from counting stored rising edges and grouping them by hour, which a historian query with script post-processing or a gateway tag-change script writing one row per activation both achieve.

What SQL groups stored events into hourly counts?

Group the event rows by the hour of their timestamps and sum one per error number, for example SELECT dateformat(t_stamp, 'HH:00') AS hour, SUM(CASE WHEN errorNum = '1' THEN 1 ELSE 0 END) AS error1 FROM error_table WHERE t_stamp >= '2024-03-05 06:00:00' AND t_stamp < '2024-03-05 14:00:00' GROUP BY hour ORDER BY hour. A lookup() expression in Perspective then pulls each label's value from that result.

Keep reading

  • Troubleshooting

    Aggregation Matrix report fails when tag count rises

    The failing report is the bigger aggregate workload even though it covers a shorter time range: report size follows tags times intervals, not the date span. The error name identifies the database function that was executing, not the cause. Capture the complete SQL message and test one report setting at a time.

    Edge computing and IIoT

  • Troubleshooting

    Ignition historian logs memory tags but not OPC tag changes

    Memory tags record because their history subscription was created fresh; the migrated OPC tags carry a stale recording subscription that a storage-provider field edit alone does not rebuild. Fix one tag first: disable history, save, re-enable history with the production provider, and save again, then verify with one safely forceable fault before batching across the remaining tags.

    Edge computing and IIoT

  • How-to

    Inhibit historian logging of one tag with a Boolean gate

    There is no per-tag inhibit command. $HistoricalLogging is global: writing 0 to it stops InTouch historical logging for the whole application. Instead, log a memory Real tag that copies the process tag only while a Boolean permits, keep the live tag updating for display and alarms, and force one catch-up copy when the inhibit clears.

    Edge computing and IIoT

Why a 16K AVEVA Edge runtime license does not set Thin Client count