# Weekly Total Flows

**URL:** <https://forum.inductiveautomation.com/t/weekly-total-flows/66142>\
**Category:** Ignition\
**Created:** [November 4, 2022, 5:31pm UTC](https://forum.inductiveautomation.com/t/weekly-total-flows/66142 "2022-11-04T17:31:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaleb.s](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@kaleb.s](https://forum.inductiveautomation.com/u/kaleb.s)\
**Post date:** [November 4, 2022, 5:31pm UTC](https://forum.inductiveautomation.com/t/weekly-total-flows/66142/1 "2022-11-04T17:31:42Z")

</div>

Trying to find the best way to create a tag historian query that will calculate weekly waterflow totals. I currently have a historical tag that calculates total daily flows with a 24 hour rest. Would i need to create a script or can it be done via StartDate and EndDate manipulation?

---

<div class="post-metadata">

**Author:** ![smcfarlane](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/smcfarlane/32/42150_2.png) [@smcfarlane](https://forum.inductiveautomation.com/u/smcfarlane)\
**Post date:** [November 4, 2022, 6:34pm UTC](https://forum.inductiveautomation.com/t/weekly-total-flows/66142/2 "2022-11-04T18:34:20Z")

</div>

Will it always be 1 weeks worth of flow data or do you want the start and end date to be variable?

---

<div class="post-metadata">

**Author:** ![kaleb.s](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@kaleb.s](https://forum.inductiveautomation.com/u/kaleb.s)\
**Post date:** [November 4, 2022, 6:47pm UTC](https://forum.inductiveautomation.com/t/weekly-total-flows/66142/3 "2022-11-04T18:47:19Z")

</div>

It would be current week of flow data. Like Mondays date TO now() and so fourth. I would need it to reset that data and start fresh Monday morning at 12:01am.

---

<div class="post-metadata">

**Author:** ![djs](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@djs](https://forum.inductiveautomation.com/u/djs)\
**Post date:** [November 4, 2022, 7:20pm UTC](https://forum.inductiveautomation.com/t/weekly-total-flows/66142/4 "2022-11-04T19:20:38Z")

</div>

You could probably just use a calculation:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/3/e30a105e5fe0c9623ae343d4cb625eeef669b72b.png)  
and adjust your _start_ and _end_ dates to go back to "last Monday".  
(use [system.tag.queryTagCalculations - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/system.tag.queryTagCalculations) if doing this in script)

---

<div class="post-metadata">

**Author:** ![kaleb.s](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@kaleb.s](https://forum.inductiveautomation.com/u/kaleb.s)\
**Post date:** [November 7, 2022, 1:44pm UTC](https://forum.inductiveautomation.com/t/weekly-total-flows/66142/5 "2022-11-07T13:44:53Z")

</div>

Is it possible to go back to last monday without doing scripting? "Last Monday" would have to be defined right?

---

<div class="post-metadata">

**Author:** ![smcfarlane](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/smcfarlane/32/42150_2.png) [@smcfarlane](https://forum.inductiveautomation.com/u/smcfarlane)\
**Post date:** [November 7, 2022, 2:25pm UTC](https://forum.inductiveautomation.com/t/weekly-total-flows/66142/6 "2022-11-07T14:25:42Z")

</div>

I can't think of a simple way to do this without scripting. Don't shy away from it. Ignitions documentation is quite good and you always have the forums here to help. You can set up a scheduled gateway event every monday and use the current date and current date - 7 days (use the system.date functions) as parameters for your query.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/e/4ee91549b2e32c5fa18dbbc31900437362463be7.png)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [November 7, 2022, 3:18pm UTC](https://forum.inductiveautomation.com/t/weekly-total-flows/66142/7 "2022-11-07T15:18:15Z")

</div>

Without scripting, I don't know. Maybe expressions can do it.

Scripting it is not too hard though:

```python
now = system.date.now()
now.setHours(0)
now.setMinutes(0)
now.setSeconds(0)

day = now.getDay()
last_monday_midnight = system.date.addDays(now, day-1)

```

There might be a way to set the time in one line with `setTime` but I couldn't make it work for some reason.  
There might also be simpler ways, but frankly I wouldn't spend more than 3 minutes on something like this.
