TIME Functions - TIMEGT(x), TIMELT(x), TIMEEQ(x)
The time functions retrieve all records for the tags and then accumulates the time the value matches the criteria. It "holds last value" and data does not need to be logged every minute.
WARNING: The TIMEGT(x), TIMELT(x), TIMEEQ(x) DO NOT SUPPORT Filtering. Any entries in the Filter Data section are ignored when the Statistic is TIMEGT(x), TIMELT(x), TIMEEQ(x).
Example #1: Calculate Number of minutes Pump1_Status was > 24. Data is logged when the tag value changes.

TIMEEQ(24) returns 139.0667

Example 2: Import the Number of minutes Pump1_On was = 1. Data is logged every 5 minutes

TimeEQ(1) returns 60 for 9/23/2014:

TWA Function - Time Weighted Average Function
Typically, this function is used when data is logged on change (not on a fixed frequency).
Example #1: Calculate the time weighted average for the FIT_I_FLOW tag. The units of the tag are "GPH", therefore no scaling is required.

TWA returns 18.43556 for the midnight to 1AM hour.

Explanation of calculation.
1st calculate the amount of seconds that the value was 10 in the hour:
910 (15 minutes * 60 + 10)
Multiply the number of seconds with the value 10 = 9100
2nd calculate the number of seconds the value was 20 in the hour:
1823 (30 minutes * 60 + 33)
Multiply the number of seconds with the value 20 = 36460
3rd calculate the number of seconds the value was 24 in the hour:
867 (14 minutes * 60 + 27)
Multiply the number of seconds with the value 24 = 20808
Sum the totals
66368 (9100 + 36460 + 20808)
Divide the sum with the number of seconds in the hour
18.43556 (66368 / 3600 seconds in hour)
Example 2 - TWA with Filtering
Get the Time Weighted Average when the UV system is on (Tag 16478 is greater than zero) for Tag 33305 for the 10AM hour.

The following query is executed to group the data by minute in the hour. We then fill in the data using a hold last value algorithm, apply the filter and average the unfiltered values:
select
IIF(Source.Timestamp IS NOT NULL,Source.Timestamp,Filter.Timestamp) as TimeStamp,savg,favg from
(select AVG(VALUE) as savg, cast (cast(month(DateStamp) as varchar) + '/' + datename(day,DateStamp) + '/' +datename(year,DateStamp) + ' ' + datename(hour,DateStamp) + ':' + datename(minute,DateStamp) + ':00' as datetime) as timestamp
from ModestoData
where DateStamp >= '2026-04-30 10:00:00' and DateStamp < '2026-04-30 11:00:00' and TAG='33305'
group by cast (cast(month(DateStamp) as varchar) + '/' + datename(day,DateStamp) + '/' +datename(year,DateStamp) + ' ' + datename(hour,DateStamp) + ':' + datename(minute,DateStamp) + ':00' as datetime)) source FULL OUTER JOIN
(select AVG(VALUE) as favg, cast (cast(month(DateStamp) as varchar) + '/' + datename(day,DateStamp) + '/' +datename(year,DateStamp) + ' ' + datename(hour,DateStamp) + ':' + datename(minute,DateStamp) + ':00' as datetime) as timestamp from ModestoData
where DateStamp >= '2026-04-30 10:00:00' and DateStamp < '2026-04-30 11:00:00' and TAG='16478'
group by cast (cast(month(DateStamp) as varchar) + '/' + datename(day,DateStamp) + '/' +datename(year,DateStamp) + ' ' + datename(hour,DateStamp) + ':' + datename(minute,DateStamp) + ':00' as datetime)) filter on source.timestamp=filter.timestamp
ORDER BY IIF(Source.Timestamp IS NOT NULL,Source.Timestamp,Filter.Timestamp) ASC
