# Sum first 12 rows of a dataset

**URL:** <https://forum.inductiveautomation.com/t/sum-first-12-rows-of-a-dataset/25652>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [June 7, 2019, 7:28pm UTC](https://forum.inductiveautomation.com/t/sum-first-12-rows-of-a-dataset/25652 "2019-06-07T19:28:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neil\_B](https://avatars.discourse-cdn.com/v4/letter/n/e95f7d/32.png) [@Neil\_B](https://forum.inductiveautomation.com/u/Neil_B)\
**Post date:** [June 7, 2019, 7:28pm UTC](https://forum.inductiveautomation.com/t/sum-first-12-rows-of-a-dataset/25652/1 "2019-06-07T19:28:46Z")

</div>

I’m trying to sum the first 12 rows of a dataset. Currently I have a total of all the rows.

pds=system.dataset.toPyDataSet(data)  
total = 0

for row in pds:  
total += row[2]

print (total)

How do I only sum the first 12 (assuming there are more than 12)?

---

<div class="post-metadata">

**Author:** ![grietveld](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/grietveld/32/6984_2.png) [@grietveld](https://forum.inductiveautomation.com/u/grietveld)\
**Post date:** [June 7, 2019, 7:30pm UTC](https://forum.inductiveautomation.com/t/sum-first-12-rows-of-a-dataset/25652/2 "2019-06-07T19:30:23Z")

</div>

Might be an even easier route, but could use a while loop instead of a for loop. That will let you specify the number of iterations versus using the full row quantity.

[https://www.w3schools.com/python/python\_while\_loops.asp](https://www.w3schools.com/python/python_while_loops.asp)

---

<div class="post-metadata">

**Author:** ![Neil\_B](https://avatars.discourse-cdn.com/v4/letter/n/e95f7d/32.png) [@Neil\_B](https://forum.inductiveautomation.com/u/Neil_B)\
**Post date:** [June 7, 2019, 7:49pm UTC](https://forum.inductiveautomation.com/t/sum-first-12-rows-of-a-dataset/25652/3 "2019-06-07T19:49:07Z")

</div>

Yeah, I’m not sure how to apply a count while iterating though the “rows in pds:”

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [June 7, 2019, 7:54pm UTC](https://forum.inductiveautomation.com/t/sum-first-12-rows-of-a-dataset/25652/4 "2019-06-07T19:54:06Z")

</div>

`total = sum([row[2] for row in pds[:12]])`

---

<div class="post-metadata">

**Author:** ![Neil\_B](https://avatars.discourse-cdn.com/v4/letter/n/e95f7d/32.png) [@Neil\_B](https://forum.inductiveautomation.com/u/Neil_B)\
**Post date:** [June 7, 2019, 8:05pm UTC](https://forum.inductiveautomation.com/t/sum-first-12-rows-of-a-dataset/25652/5 "2019-06-07T20:05:35Z")

</div>

Ahh, I was trying to add the limit to row. Awesome thanks
