Conditional tag calculations

I'm using system.tag.queryTagCalculations to calculate min, max, average, etc over a day for a bunch of tags. All works great, yay.

However - I now have a requirement to do conditional summaries as well, where the summary only includes time when a different tag is on a certain value. For instance, average value of a float tag while another INT tag is reading 1 (which could be used to give me something like average flow into a plant, but only while that plant was on Product).

Is there a nice way of doing this that I just haven't stumbled across yet? Or do I need to pull down all the data for each tag and do a whole bunch of processing myself?

You will have to do a whole bunch of processing yourself.

FWIW, in projects where this is expected to be needed, I do not use the tag historian. Wide tables that record the possible conditions in the same rows as the values of interest make this sort of thing nearly trivial in standard SQL. Which would be populated by SQL Bridge transaction groups or the scripted equivalent.