How to calculate using AF expressions the total time within a time range where the value is between a value range? Running analyses at each new value to do a comparison is not an option as the values update very frequently.

How to calculate using AF expressions the total time within a time range where the value is between a value range? Running analyses at each new value to do a comparison is not an option as the values update very frequently.

We have almost this exact example in our public class when we have students practice expression syntax (link to class workbook below if interested). Basically you use two similar TimeXX functions and take the difference to get the total time in the value range. The only kind of tricky thing is deciding how you want to handle the boundary values; do you want to include or exclude times when the tag is exactly equal to a boundary value?

For example, if you want to

**exclude**times when the value is equal to either boundary, you could use the following for a time range of yesterday and boundary values of 10 and 90:

TimeLT('Attribute','y','t', 90) - TimeLE('Attribute','y','t',10)

Use other functions if you want to handle boundary conditions differently.

Please let us know what you think or if you have any further questions.

AF Class workbook: https://osicdn.blob.core.windows.net/learningcontent/pdfs/Building%20PI%20System%20Assets%20v2018%20SP2.pdf

You can use a combination of the TimeGE (Time greater than or equal to) and TIMELE (Time less than or equal to) functions and setup an analysis to calculate when the value of an attribute was in a specific time range. More information can be found here:

1. TIMEGE -

Best,

Pranav