### Aggregation Mode

The **Aggregation** **Mode** dictates what happens when multiple raw values are encountered for a given sample window (the size of which is determined by the number of requested rows, or the interval size).

Aggregation Mode | Description |
---|

Time-weighted Average | The values are averaged together, weighted for the amount of time they cover in the interval. |

Min/Max | The minimum and maximum values will be returned for the window. In other words, two rows will be returned. If only one value is seen in the interval, only one row will be returned. |

Closest Value | The value closest to the ending time of the interval will be returned. |

Basic Average | The values are summed together and divided by the number of values. |

Sum | The values in the interval are summed together. |

Maximum | The maximum value in the interval. |

Minimum | The minimum value in the interval. |

Duration On | Returns the number of seconds that the value was recorded as non-zero. |

Duration Off | Returns the number of seconds that the value recorded as zero. |

Count On | Returns the number of times the Tag's value went from a zero value to non-zero. |

Count Off | Returns the number of times the Tag's value changed from a non-zero value to zero. |

Count | Returns the number of times a value was recorded |

Percent Good | Time-weighted percentage of good values over the date range. |

Percent Bad | Time-weighted percentage of bad values over the date range. |

Range | Returns the range between the highest and lowest value for the period. |

Standard Deviation | Standard Deviation - Returns the standard deviation of values, or how much spread is present in the data; low standard deviation shows the values are close to the mean, and high standard deviation shows that the data points are spread out over a large range of values. Only good quality values are used when calculating |

Variance | Returns the variance of values. Similar in concept to standard deviation. Only good quality values are used when calculating. |

### Sample Size

The sample size determines how many data points will be returned from the query.

#### On Change

An On Change query will return points as they were logged, and can be thought of as a "raw" query mode. This means that the results may not be evenly spaced. Also, it is important to note that every changed value will result in a row, and therefore if you are querying multiple tags and once, you may end up with more rows than you anticipated. For example, if Tag A and Tag B both change, you would end up with [[A_{0}, B_{0}],[A_{1}, B_{0}], [A_{1}, B_{1}]].

If you want to essentially retrieve raw values, while coalescing them down into fewer rows, try using the Interval sample mode, with an interval set to your largest acceptable time between rows, and select "prevent interpolation" from the advanced settings.

#### Natural

A Natural query will look up the logging rate for the queried tags (when possible), and return results spaced apart at that rate. This means that the return size will vary with the date range.

#### Fixed

You can use the **Sample Size** and **Aggregation Mode** on the **Tag History** binding type to fix the number of records that are retrieved. The Fixed sample size will cause the binding to retrieve all records from the date range, and aggregate them evenly between a fixed number of points. This will ensure that the number of rows will remain the same without regard to the size of the dataset. In windows where users are able to select a large range of data, Fixed is recommended as it will prevent the property from loading an excessive number of records.

In cases where the number of points can not evenly represent the data from the date range, an extra point will be added, making the final size of the dataset the fixed value + 1.

Selecting the **Min/Max** aggregation mode returns two rows of data for every row requested. Each pair represents a minimum and a maximum result from the underlying data. Therefore, a table with a fixed length, would return double the requested amount with Min/Max aggregation mode selected. With Min/Max aggregation mode selected, and with a fixed row length of one, the data set returns the oldest tag value of the time range

The following image shows a Tag History Binding pulling data from the last one day. The **Sample Size** is configured to Fixed with a value of 100, and the **Aggregation Mode** is set to Basic Average. This means that the binding will query for data from the last one day, regardless of how many records there are, and create 100 time-slices that are evenly dispersed between the start and end periods of that range. Then, a basic average of the tag values are calculated for each time-slice. The resulting values are then returned to the property.

Note the **Insert Property**icon next to **Sample Size**. This allows a property binding to determine the number of data points, so you could change the size to increase or reduce the amount data points on the chart from the client.

#### Interval

Where as the **Fixed** sample size will calculate time slices based on the date range, the **Interval** sample size allows you to determine the size of the time slices. This sample size will divide the date range by the interval size to determine the size of each slice. Because of this, it is recommended to use an interval that is evenly divisible by the date range. However, in the event that the date range is dynamic or user driven, interpolation will handle any partially built slices. Even though the binding may attempt to evenly distribute the slices, there may be an extra row that represents the current values as they are building an interval.

The image below shows a **Realtime** range of 60 minutes. The **Aggregation Mode** is set to **Time-weighted Average**, and the **Sample Size** is set to** Interval** 5 minutes. This means that the binding will query for data ranging from 60 minutes ago to now (or whenever the binding last executed, in the case that polling has been turned off). That 60 minute window will be divided as evenly as possible into 5 minute time-slices, so there should around 12 time-slices. Each time slice will aggregate its value based on the time-weighted average of all values within that slice.

The example uses a Realtime range, but a Historical range could easily be used instead.

Note the **Insert Property**icon next to **Sample Size**. This allows a property binding to determine the number of data points, so you could change the size to increase or reduce the amount data points on the chart from the client.