# KPI calculation by AF Analytics

**jancapelle**Jul 5, 2016 10:47 AM

Hi all,

we are currently trying to implement some technical KPIs. On some reports, these KPIs are going to be compared between different sites in order to determine the sites on which an intervention has to be performed with a high priority.

In a first approach, using AF Analytics (especially for the use of template) seems a good idea.

For example, 2 temperatures (Temp A and Temp B) are recorded in 2 PI Tags on a hourly basis.

And KPI = Min( (Number of readouts with Temp A < 50°C / Number of readouts Temp A), (Number of readouts with Temp B < 32°C / Number of readouts Temp B)) * 100%

On the reports (which won't probably be implemented with PI tools), this KPI will be visualized at least on a daily basis but the user will have the possibility to change the period.

3 questions :

- I didn't find a function in PI Analytics which allows to count the number of readout below a threshold. Is there an other way to implement this KPI than adding a new PI tag containing all Temperatures below these thresholds?

- To calculate this KPI on a daily basis, I guess this calculation has to be triggered each day at midnight for the previous day. If, for some reason, the temperatures for the previous day are stored in PI with some delay (for example break in communication with telemetry system), is there a possibility to automatically backfill the results of this KPI?

- If we want to visualize the value of this KPI for example for one week, the average of the daily KPI value will be wrong (in case of different number of readouts per day). So, in order to do that, shall we implement this calculation directly in the reports (for example by the use of PI OLEDB)? In order to do that, regarding performances, maybe it's better to store in PI tags the number of readouts (for Temp A, temp B, Temp A below threshold, Temp B below threshold). What do you think about it?

Thanks in advance for your answers,

Regards,

Jan