The most efficient way to do this programmatically is to use the RecordedValues()
function to retrieve all Events for the given period, and then to apply FilterData()
to apply your chosen conditions. Then a simple Avg()
will get your answer.

This falls into the category of 'expensive calculations', as you are retrieving 24h of data and then performing a complex function on every event within it. So take care doing things like this at scale - always consider aspects like scheduling to avoid impact to the archive at busy times.
For example, it is common for Data Archives and Analytics to be especially busy at midnight or at the beginning or end of another given cycle period. So whilst you may want the answer to be for 00:00-00:00 and land on the midnight timestamp, you might be better applying an offset to the scheduling.
So if I were you, I'd perhaps schedule this kind of analysis at 2:13am, grabbing data from 'y'
to 't'
and then output the result to the 't'
timestamp. Especially if you have lots of them running. For new PI AF Developers I'd always recommend having an expert check over calcs like this before you publish them to Production, to ensure that they are as performant as possible.