I want to build an analysis in AF that will calculate a running total that resets daily from 6 am to 6 am. The big issue is the part between midnight and 6 am. The whole offset in the calculation makes everything a little more difficult. I and others at my site have tried doing this a hundred different ways each more complicated than the last. We would like to do this for many different tags so if we could figure out a way to do this simply and be able to transfer it to different tags would be great.

Things we have figured out so far:

Periodically triggered, every hour.

Series of If/Then statements.

Referencing time with '*" and 'y' and 't' along with +/- '6h'.

Using TagTot()

Any help would be great. We are at a loss.

Hey All, I am the OP. Thank you all for your help. I used bits and pieces of all of your input and got a running total working. It can run for 6am to 6am or 4pm to 4pm, etc etc. You just need to switch the numbers around. I will explain each part.

Here is an example with 10am to 10am. So the way this works is that at 10am every day, the running total resets and starts at 0. (See graph)

The first variable is just the current time in hours because I didn't want to clutter up the rest of my calculation.

The second variable totalizes the flow of gas from today at midnight (00:00 not 24:00) to now.

The third variable totalizes the flow of gas from today at 10am to now.

The fourth variable totalizes the flow from today at 10 am to today at midnight (24:00 not 0:00). You can also think of it as yesterday at 10 am to today at midnight (0:00 not 24:00).

The fifth variable is where I mapped my output tag. Basically, let's say it is today, Feb 19 (Because I need more relative time to explain this coherently). If it is Feb. 19 before 10 am, then I want to totalize from 10am Feb 18 to the time now on Feb 19. In non-date time, I want yesterday at 10 am to now. You can see that I split it up in two parts, from 10am to midnight and from midnight to now because I needed to simplify it in my brain to understand it better. You could combine those two. If it is after 10 am on Feb 19, I want my totalization to start over at 10am so I used my Ten to now variable, which totalizes the gas flow from 10 am on Feb 19 to now, 12:30 pm. If it was 10 am, it would be zero.

To make this calculation work, I did two interesting things. First, I made it periodically triggered with a period of 15 min (bc they wanted more constant update on this value) and I made an offset of 10 seconds. Without that offset, this calculation doesn't work well.

The second thing I did that was weird was in the fifth variable. Originally I had if ( TimeNow <=10 ) instead of 9 and I was getting a totalization that looked like this:

Just looking at it, you can tell this is a graph of a running total that resets periodically. If you look closer, you can see that it doesn't reset and start at 0. And if you look at the time stamp, you can see that it resets at around 11 am. I actually spoke to a PI afficianado in my company about this and he suggested I do ( TimeNow <=9 ) instead of 10 because then when it did reach 10, with my offset, it would actually reset at 10. (Correct me if I'm not thinking about this the right way, It's still a little fuzzy in my brain.) Anyways, bippiddi boppiddi boo, I have a running total that works.

By changing the references, this calculation can be used for any non-midnight reset running total calculations, which, for my location, is huge and I have already started using this elsewhere because it works.

Feel free to add any remarks or anything if you can add on a more technical explanation. I am not a PI guru but I am a power user. I decided to update this thread with my solution because I wanted to share what worked for me.