# Counter per shift

**URL:** <https://forum.inductiveautomation.com/t/counter-per-shift/16362>\
**Category:** Ignition\
**Created:** [December 19, 2017, 4:34pm UTC](https://forum.inductiveautomation.com/t/counter-per-shift/16362 "2017-12-19T16:34:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![santiago4ever72](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@santiago4ever72](https://forum.inductiveautomation.com/u/santiago4ever72)\
**Post date:** [December 19, 2017, 4:34pm UTC](https://forum.inductiveautomation.com/t/counter-per-shift/16362/1 "2017-12-19T16:34:26Z")

</div>

Is it possible to create a counter per shift where I have a tag that gives me a global accumulation eg. Bottles\_per\_production\_day=45,032 but I want the bottles per shift  
Shift 1 (5am-1pm)= 15,350 bottles  
Shift 2 (1pm-9pm)= 16,480 bottles  
Shift 3 (9pm-5am)= 13,202 bottles

and when another day passes it would reset to 0 each of the shifts to be able to start the accumulation again.  
Is this possible?

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [December 20, 2017, 12:53pm UTC](https://forum.inductiveautomation.com/t/counter-per-shift/16362/2 "2017-12-20T12:53:27Z")

</div>

You can create an expression tag to determine the current shift number based on the current time, example expression:

```auto
if(getHour24(now()) < 5,
  3,
  if(getHour24(now()) < 13,
    1,
    if(getHour24(now()) < 21,
      2,
      3
    )
  )
)

```

Then make a trigger script on it to set the next counter to 0 when the shift changes. And use this value to determine what counter to increase (the details depend on what you use to count).

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 20, 2017, 1:46pm UTC](https://forum.inductiveautomation.com/t/counter-per-shift/16362/3 "2017-12-20T13:46:31Z")

</div>

One possibility would be to log the value of the tag at the end of the the shift. You can then either use a query to do the math, or use a script.

You could also, as an alternative, log it every hour and get hourly counts (managers seem to love that kind of stuff 😉)

---

<div class="post-metadata">

**Author:** ![santiago4ever72](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@santiago4ever72](https://forum.inductiveautomation.com/u/santiago4ever72)\
**Post date:** [December 20, 2017, 6:50pm UTC](https://forum.inductiveautomation.com/t/counter-per-shift/16362/4 "2017-12-20T18:50:28Z")

</div>

This is the way that we are trying to do it. Thing is we want to log it every shift but also show it in real-time on the dashboard.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 20, 2017, 6:57pm UTC](https://forum.inductiveautomation.com/t/counter-per-shift/16362/5 "2017-12-20T18:57:18Z")

</div>

> [@santiago4ever72](#):
>
> Thing is we want to log it every shift but also show it in real-time on the dashboard.

Consider using an odometer-style counter that never resets. Log its value to the database at any desired pace, or faster. Then subtract one value from any previous value for the production over that interval. Subtract the current value from any previous value for the live count since that sample.

---

<div class="post-metadata">

**Author:** ![santiago4ever72](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@santiago4ever72](https://forum.inductiveautomation.com/u/santiago4ever72)\
**Post date:** [December 20, 2017, 7:43pm UTC](https://forum.inductiveautomation.com/t/counter-per-shift/16362/6 "2017-12-20T19:43:41Z")

</div>

But is it possible to make a counter per shift of an already existing tag to be able to show in real time the accumulation per shifts? In my case I have a tag that gives me the water usage in hectoliters for a specific order. I already put this to save in the database using transaction groups and I included my shifts and order number in the table. Would it be possible to achieve this by some sort of scripting or query tag?

---

<div class="post-metadata">

**Author:** ![santiago4ever72](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@santiago4ever72](https://forum.inductiveautomation.com/u/santiago4ever72)\
**Post date:** [December 20, 2017, 7:53pm UTC](https://forum.inductiveautomation.com/t/counter-per-shift/16362/7 "2017-12-20T19:53:16Z")

</div>

We are just trying to get real time data while at the same time trying to store that specific value. In this case it would be the water consumption on a specified shift with a specified order/batch number.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 20, 2017, 8:12pm UTC](https://forum.inductiveautomation.com/t/counter-per-shift/16362/8 "2017-12-20T20:12:58Z")

</div>

You could run a query that sums the quantities for batches that finished within a particular shift, and add the live qty for the current shift. It gets tricky accounting for batches that start in one shift and end in a later shift.
