# Counting product tag on ticket

**URL:** <https://forum.sambapos.com/t/counting-product-tag-on-ticket/22692>\
**Category:** V5 Question\
**Created:** [August 4, 2020, 1:24pm UTC](https://forum.sambapos.com/t/counting-product-tag-on-ticket/22692 "2020-08-04T13:24:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![markjw](https://forum.sambapos.com/user_avatar/forum.sambapos.com/markjw/32/9942_2.png) [@markjw](https://forum.sambapos.com/u/markjw)\
**Post date:** [August 4, 2020, 1:24pm UTC](https://forum.sambapos.com/t/counting-product-tag-on-ticket/22692/1 "2020-08-04T13:24:59Z")

</div>

I am trying to implement an item count on the kitchen ticket, so the staff know how many physical items need to go in a bag. It isn’t just the quantity, as some dishes may consist of 2 or more “items” so must be counted as such.

I have added a Custom Product Tag for `Item Count` to store the number of items each product consists of.

I can get it to show the sum of this on the ticket as follows:

```auto
[=F('{ORDER DETAILS:MT.Item Count.Sum}','0')]

```

However, the above does not take the quantity into account - it just takes as each order with 1 quantity. I’ve tried

```auto
[=F('{ORDER DETAILS:(MT.Item Count * O.Quantity).Sum}','0')]

```

But that just returns nothing.

I wonder if anyone else has came across needing to do this and has a quick solution?

---

<div class="post-metadata">

**Author:** ![JTRTech](https://forum.sambapos.com/user_avatar/forum.sambapos.com/jtrtech/32/21270_2.png) [@JTRTech](https://forum.sambapos.com/u/JTRTech)\
**Post date:** [August 4, 2020, 1:34pm UTC](https://forum.sambapos.com/t/counting-product-tag-on-ticket/22692/2 "2020-08-04T13:34:32Z")

</div>

Maybe try separating the two fields into seperate tn expressions with the \*? :-/

---

<div class="post-metadata">

**Author:** ![markjw](https://forum.sambapos.com/user_avatar/forum.sambapos.com/markjw/32/9942_2.png) [@markjw](https://forum.sambapos.com/u/markjw)\
**Post date:** [August 4, 2020, 1:41pm UTC](https://forum.sambapos.com/t/counting-product-tag-on-ticket/22692/3 "2020-08-04T13:41:03Z")

</div>

That won’t work, because what we have is like this:

```auto
Item Count Qty Total
1 1 1
2 1 2
2 2 4
------------------------
5 4 7

```

So we need it to show 7, but right now it will show 5 (total of individual `Item Count` values). If I just took the sum of `Item Count` and added the sum of `Quantity`, I would get `5+4=9`. So what I need is for each row, the 2 values multiplied (Item Count \* Quantity) then the sum of that new value.

---

<div class="post-metadata">

**Author:** ![Posflow](https://forum.sambapos.com/user_avatar/forum.sambapos.com/posflow/32/63001_2.png) [@Posflow](https://forum.sambapos.com/u/Posflow)\
**Post date:** [August 4, 2020, 2:08pm UTC](https://forum.sambapos.com/t/counting-product-tag-on-ticket/22692/4 "2020-08-04T14:08:05Z")

</div>

I am on the phone now but wouldn’t MT.Tag.count be the right syntax?

---

<div class="post-metadata">

**Author:** ![Bob\_be](https://forum.sambapos.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@Bob\_be](https://forum.sambapos.com/u/Bob_be)\
**Post date:** [August 4, 2020, 2:48pm UTC](https://forum.sambapos.com/t/counting-product-tag-on-ticket/22692/5 "2020-08-04T14:48:54Z")

</div>

What if you kept a running total as orders are added, using program settings?

---

<div class="post-metadata">

**Author:** ![markjw](https://forum.sambapos.com/user_avatar/forum.sambapos.com/markjw/32/9942_2.png) [@markjw](https://forum.sambapos.com/u/markjw)\
**Post date:** [August 4, 2020, 3:18pm UTC](https://forum.sambapos.com/t/counting-product-tag-on-ticket/22692/6 "2020-08-04T15:18:13Z")

</div>

> [@Posflow](#):
>
> MT.Tag.count

No, that will give the `Count` as the number of records and also would not consider the quantity of the order.

> [@Bob\_be](#):
>
> What if you kept a running total as orders are added, using program settings?

The data is already stored on the ticket so its just really finding the way to access it as a sum value taking quantity into account. This would be more like an overworked way of doing it and would have to handle lots of extra scenarios like when you change tickets having to recount, etc. All I need is to get the value including each item count being multiplied by quantity.

---

<div class="post-metadata">

**Author:** ![markjw](https://forum.sambapos.com/user_avatar/forum.sambapos.com/markjw/32/9942_2.png) [@markjw](https://forum.sambapos.com/u/markjw)\
**Post date:** [August 4, 2020, 4:02pm UTC](https://forum.sambapos.com/t/counting-product-tag-on-ticket/22692/7 "2020-08-04T16:02:54Z")

</div>

Ok I got it working now 🙂

```auto
[=F('{ORDER DETAILS:([MT.Item Count]*[O.Quantity]).Sum}','0')]

```

By putting the values in `[]` means they get processed on SQL Server rather than in SambaPOS. I knew it would be related to doing this but I couldn’t remember the syntax and took a lot of trial and error searching various things until I found an example.

Here is an example ticket, based on the table I used above. Both the Chicken Balls and Pork Balls have `Item Count=2` (they come with the sauce separate), so you can see here with the expression it correctly shows the total items as 7.

![Samba.Presentation_2020-08-04_17-00-16](https://forum.sambapos.com/uploads/default/original/3X/f/f/ff8c1ed1a7d3d8261a7750fe84e85b5fd98816e0.png)
