IMD SolutionComputing LibraryShop main store

How-to

Show a historian tag average over three days on an HMI

Edge computing and IIoT Published 10 min read

Short answer

Bind the HMI display directly to the historian's summary average over a defined three-day window: request the Average aggregate with explicit start and end timestamps and a cycle count of 1. Write the result to a second tag only when a trend, report, or another client must read the average as its own value, and give that tag a floating-point type.

On this page
  1. Do you need the average displayed or stored in a tag?
  2. What does three days mean: a rolling window or three calendar days?
  3. How do you get one average for the whole window from the historian?
  4. Why does the historian average differ from the average of the raw samples?
  5. How do you bind the average to the HMI display?
  6. How do you write the average into a second tag for trending?
  7. How often should a rolling three-day average refresh?
  8. How do you verify the number before operators rely on it?
  9. Questions asked

Bind the HMI display to one summary average that the historian computes over an explicitly defined three-day window; that is the whole answer. Ask the historian for the Average aggregate of Tag_1 between explicit start and end timestamps with the cycle count set to 1, check the number against a hand calculation, and write it into Tag_2 only when a trend, a report, or another client must read the average as a value of its own. The names below — AnalogSummaryHistory, Average, wwCycleCount — are the documented AVEVA Historian summary-retrieval names; other historians keep the same request shape with their own table and aggregate names.

Do you need the average displayed or stored in a tag? #

Bind the display directly to the historian's summary result when the only requirement is showing the number, and create or write Tag_2 only when a trend, a report, or downstream logic must read the average as a value of its own.

Tag_1 is the historized raw value and Tag_2 is the proposed home for the average, but the two jobs behind those names are separate: a graphic that must show a number needs no process tag at all, while a stored value needs a writable destination, a data type, and an update mechanism.

Requirement Where it is met Check next
Show the current three-day average Graphic binding to a summary result, or a query result assigned to the display property Window definition and refresh schedule
Expose the average as Tag_2 Writable numeric tag plus an assignment from the validated summary result Write access, floating-point type, trigger
Trend past averages History collection enabled on Tag_2 Storage: one row per refresh

Prefer the direct binding for display-only duty: it removes an intermediate write, its refresh handling, and its quality propagation. Storing successive averages in Tag_2 creates a new history — one average per write — which never reproduces the raw signal, so Tag_1's collection stays untouched in every variant.

What does three days mean: a rolling window or three calendar days? #

Decide this first, because a rolling 72 hours ending now and the previous three complete calendar days give different numbers from the same tag: the rolling window always contains the most recent hours of live operation, while the calendar window ends at a fixed midnight.

Both are legitimate requests; they are just different numbers.

  • Rolling 72 hours. StartDateTime = now minus 72 h, EndDateTime = now. The value moves with time, so it needs the refresh schedule described further down.
  • Three calendar days. StartDateTime = 00:00 three days ago, EndDateTime = 00:00 today. The value is fixed until midnight and matches what a daily report means by 'the last three days'.

A disagreement of even 20 minutes at the window edges changes the result by whatever the process did in those 20 minutes. Keep both endpoints on one time basis — the basis in which the historian stores and returns timestamps — and confirm the client is not shifting one endpoint across a time-zone or daylight-saving boundary. Commit to the definition the operators expect ('since this time three days ago' is rolling; 'the three full days before today' is calendar) and print the interval next to the displayed value during commissioning, so a wrong window is visible on the first shift.

How do you get one average for the whole window from the historian? #

Request the summary with the average calculation, the tag name, and explicit start and end timestamps, and set the cycle count to 1 so the historian returns a single value covering the whole 72 hours instead of one row per interval.

On AVEVA Historian, analog summary retrieval runs as SQL against the historian's schema, and the summary rows for analog tags live in AnalogSummaryHistory:

SELECT Average
FROM AnalogSummaryHistory
WHERE Tagname = 'Tag_1'
  AND StartDateTime >= DATEADD(DAY, -3, GETDATE())
  AND EndDateTime < GETDATE()
  AND wwCycleCount = 1

One trap sits in the window expression: the bare fragment (DAY, -3, GETDATE()) is not a valid date calculation on the SQL Server instance behind the historian. Wrap it in DATEADD as shown, or substitute explicit datetime literals when you want the fixed calendar window from the previous section. DATEADD(DAY, -3, GETDATE()) is standard T-SQL; a historian on another database backend has its own documented date arithmetic.

wwCycleCount is the documented control for how many summaries the retrieval returns across the window: 1 gives one summary covering all of it, a larger count gives that many equal slices. Confirm one row comes back before anything is bound — a row per hour is an hourly trend, not a three-day average.

The SQL transport is optional: AVEVA documents more than one way to retrieve a summary average, including summary data types inside graphics, and other platforms expose the same request as script functions with an average aggregate. The request itself — tag, window, Average, single cycle — is not optional.

Why does the historian average differ from the average of the raw samples? #

Use the historian's time-weighted summary average, not the arithmetic mean of the stored samples: with exception-based collection the samples are unevenly spaced, and the sample mean is biased toward whatever the process was doing when the historian happened to store a value.

The historian's Average is time-weighted: each sample counts for as long as it held, not once per sample. Plant data is stored exception-based — a new row only when the value changes past a deadband — so stored samples are unevenly spaced and a plain sample mean is wrong in a predictable direction.

Worked example, one 72-hour window on a feeder's power draw:

Held value Duration Contribution
40 kW 50 h 40 × 50 = 2000 kW·h
55 kW 22 h 55 × 22 = 1210 kW·h

Time-weighted average = (2000 + 1210) kW·h ÷ 72 h = 44.6 kW. Arithmetic mean of the two stored samples = (40 + 55) ÷ 2 = 47.5 kW. The sample mean sits 2.9 kW — about 6.5 percent — above the true average, because it weighs the 50-hour period and the 22-hour period equally. The summary Average returns 44.6 kW, the number consistent with the energy actually consumed over the window.

This is also why the verification below insists on one summary row for the whole window: averaging several equal-length summary rows is safe, averaging samples or unequal rows is not.

How do you bind the average to the HMI display? #

Bind the numeric display straight to the summary result: in an ArchestrA or Industrial graphic that is a History Summary data type on the value element, and in script-driven clients it is the query result assigned to the display property instead of a tag reference.

A History Summary binding requests the tag, the calculation, and the window from the historian, leaving no intermediate tag, script, or write-back in the path. That data type is documented to work with Application Server object attributes intended for OMI ViewApps and managed InTouch HMI applications; outside those environments, treat it as unavailable and use the query route below.

The query route is a script: run the summary request from the previous section on a schedule or on screen open and assign the result to the display property. Ignition's queryTagHistory function documents its Average mode as the time-weighted average of all samples in the requested time slice, so the script returns exactly the number the SQL summary returns. The property side of that assignment is platform-specific: on Ignition, start from the article on whether an Ignition property can bind directly to a script. In WinCC, the same direct display is achieved by binding a calculated value to an I/O field without an intermediate tag.

The mechanics are otherwise the same as showing a historian maximum on an operator text field; the aggregate and the window are the only differences.

Write Tag_2 only when other graphics, reports, or a trend must consume the average as a value of its own: run the validated summary request through the supported database or script connection, check its status and returned interval, then assign the result with an explicit trigger.

Three checks come before the first write. Tag_2 must accept writes from the chosen mechanism; its type must be floating point, because a three-day average carries a fraction that an integer tag truncates away; and its history collection must be deliberate, since every refresh stores a row if the tag is historized.

Give the assignment an explicit trigger — the same schedule that refreshes a rolling window, or the day-boundary event for calendar days. An assignment that fires on unrelated screen activity produces a trend of display events rather than a trend of averages. Keep Tag_2 separate from Tag_1 even when both are numeric: one is raw acquisition with its own scan behavior, the other is a calculated result with its own update rate, and merging them costs the ability to trend the raw signal.

How often should a rolling three-day average refresh? #

Refresh a rolling average on a fixed schedule of 5 to 15 minutes for an operator screen: the 72-hour window moves by only 0.12 to 0.35 percent of its length in that time, so the displayed value tracks the window far closer than any operator decision needs.

The arithmetic behind that range: the window is 72 h = 4320 min, so a 5-minute refresh moves its edges by 5 ÷ 4320 = 0.12 percent of the window, and a 15-minute refresh by 15 ÷ 4320 = 0.35 percent. A display that only calculates on open is a snapshot: its endpoint freezes at open time, and by the end of a 12-hour shift the number is stale over one sixth of the window. For the calendar-days variant, one calculation at the day boundary, or on first open after midnight, is enough — the value is fixed until the next midnight by definition.

Each refresh is one summary retrieval over three days of history, and its cost depends on the same factors that decide historian data retrieval speed, such as scan rate, archive layout, and how many tags the request carries. Schedule the refresh; never hang it on screen repaint.

How do you verify the number before operators rely on it? #

Verify the chain in one pass with fixed test endpoints before the graphic goes live: raw history, query result, tag value when used, displayed value, in that order, so a fault is localized to the first step where the numbers stop matching.

  1. Pull raw history for Tag_1 across the same window in the historian's own client. A correct live value in the graphic proves nothing about whether three days of usable history exist; collection gaps and quality flags show up here first.
  2. Run the summary request with the same endpoints and confirm it returns exactly one row spanning the full window. Multiple rows mean the cycle limit did not collapse the retrieval.
  3. Hand-calculate the time-weighted average for a short sub-window — one hour of steady operation, where the answer is the held value itself — and compare it with the summary result for that slice.
  4. Compare the graphic's displayed number with the query result. A correct query with a wrong display points at the binding, the type conversion, or a refresh trigger that never fires.
  5. If Tag_2 exists, compare its value and its trend against the query history. A mismatch localizes to the assignment path: trigger, write permission, or type.
  6. Prove the failure behavior: block the retrieval (wrong credentials or a stopped service is enough) and confirm the display shows a stale or error indication. A failed retrieval must never render as 0, because a zero on this graphic reads as a legitimate process average.

The decision for each case: display only — bind the graphic to the summary average over the committed window definition and refresh on the 5-to-15-minute schedule; the average needed as a value — add Tag_2 as a floating-point tag written from the validated request on the same schedule, or at the day boundary for calendar windows; either way — one cycle, explicit timestamps, and the interval printed beside the value until operators have relied on it through one full window.

Questions asked

What does wwCycleCount do when it is set higher than 1?

It divides the retrieval window into that many equal intervals and returns one summary row per interval. wwCycleCount = 1 gives a single summary covering the whole window; 72 would give one hourly row, each an average of its own slice. Average a multi-row result yourself only when every interval has equal length and clean data, because a plain mean over unequal intervals reintroduces the sample-mean bias described above.

Does historizing the average tag add much storage?

Far less than the raw tag. The average tag stores one row per refresh: at 10-minute intervals that is 144 rows per day, regardless of how fast Tag_1 changes. If the historian's storage budget is tight, historize Tag_2 only for the retention period the average trend actually needs, and leave Tag_1's exception-based collection unchanged.

What happens to the average when the window includes bad data or an outage?

The summary is computed from whatever the historian holds, so a window that spans a communications outage or a sensor failure is suspect. How bad and missing samples are treated in a summary is product-specific and documented per historian release, in the summary-retrieval section of its documentation. Read that rule before you trust an average from a troubled period, and check the stored rows around the gap to see what the calculation actually had to work with.

Is there a way to get the average without a SQL query?

Yes. OPC HDA — Historical Data Access — defines the time-weighted average as one of its standard aggregates, so an OPC HDA client can request it for any window without touching the SQL side. Historians also expose aggregate retrieval through their scripting or API layers; the function names and aggregate lists differ by product, so take them from that product's scripting documentation rather than translating the SQL example.

Keep reading

  • Troubleshooting

    Historian trend empty: PLC tag collection troubleshooting

    A live PLC value proves nothing about what the historian stored. Work one known, changing tag through four boundaries — controller to data server, server to collector, collector to point, point to chart — and with a 2 s update rate, a 1% deadband on a 200 in span and a 24 in/h fill, a 20 min window must show about 4 stored events. Zero events means the collector; four events with a flat chart means the display.

    Edge computing and IIoT

  • Explainer

    Do you need a historian or just an OPC tag server?

    No. An OPC tag server (OPC DA) supplies the current value, quality and timestamp of each item and stores nothing, so monthly figures need a historian or a SQL logger collecting from that same server. Keep a reporting client like ActiveFactory only if you also run the historian it expects.

    Edge computing and IIoT

  • Troubleshooting

    Historian tag scaling for an unscaled PLC integer value

    Scale the tenths-encoded integer on the historian tag itself: linear scaling with gain 0.1 and offset 0 turns raw 144 into 14.4 while keeping the direct PLC acquisition. Check the tag's existing scaling first so a second divide-by-ten does not log 1.44, and repoint the tag at a SCADA-supplied value only if logging that stops with that runtime is acceptable.

    Edge computing and IIoT