# Help on Dataset

**URL:** <https://forum.inductiveautomation.com/t/help-on-dataset/49690>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [August 9, 2021, 9:59am UTC](https://forum.inductiveautomation.com/t/help-on-dataset/49690 "2021-08-09T09:59:14Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![nnaik](https://avatars.discourse-cdn.com/v4/letter/n/53a042/32.png) [@nnaik](https://forum.inductiveautomation.com/u/nnaik)\
**Post date:** [August 9, 2021, 9:59am UTC](https://forum.inductiveautomation.com/t/help-on-dataset/49690/1 "2021-08-09T09:59:14Z")

</div>

Hello everybody,  
I need help on working with dataset, I have a dataset which consist one of the column as Index to which I want to pass alternatingly value 1 ( each row in Index column would be 0,1,0,1,0,1…) so when ever user makes a new entry it will automatically assign value either 0 or 1  
Intention is I will be using a template in a template repeater and each template text will either be blue or white depending on 0 or 1 pass through Index Column template parameter.

I have tried following script but i only updates last index as shown in snapshot, I doubt that issue is with system,dataset.toDataset instruction, its not getting executed for each value of (i). I am a newbie in python programming and just taking baby steps.

Note : pls ignore Value 2 in last dataset entry it was old snap latest is 1 as sen in scripting snap

![Dataset](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/e/5efed1dbaed596a5d9807c0c52eda80028a7c5be.png)

 ![Script](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/3/7320e1b981c6878e8993ff07706ddeded8bf3822.png)  
 ![Output console](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/9/e9083062545b17423988f93ed538bd665dd43628.png)

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [August 9, 2021, 10:29am UTC](https://forum.inductiveautomation.com/t/help-on-dataset/49690/2 "2021-08-09T10:29:13Z")

</div>

To alternate between 0 and 1 for an incrementing value, use modulus.

```auto
for i in range(10):
    print i % 2

```

---

<div class="post-metadata">

**Author:** ![nnaik](https://avatars.discourse-cdn.com/v4/letter/n/53a042/32.png) [@nnaik](https://forum.inductiveautomation.com/u/nnaik)\
**Post date:** [August 9, 2021, 10:30am UTC](https://forum.inductiveautomation.com/t/help-on-dataset/49690/3 "2021-08-09T10:30:29Z")

</div>

Index column doesn’t contain any value other than what i intend to pass, I need to run through each row of Index column and set value in Index column

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [August 9, 2021, 10:39am UTC](https://forum.inductiveautomation.com/t/help-on-dataset/49690/4 "2021-08-09T10:39:41Z")

</div>

Try:

```auto
ds = event.source.parent.getComponent('Template Repeater').templateParams
ds_new = system.dataset.sort(ds, 1)

for i in range(ds_new.rowCount):
    ds_new = system.dataset.setValue(ds_new, i, 'Index', i % 2)
   
event.source.parent.getComponent('Template Repeater').templateParams = ds_new

```

Ps. you should always update your GUI _after_ you’ve finished changing values to avoid constant updates

---

<div class="post-metadata">

**Author:** ![nnaik](https://avatars.discourse-cdn.com/v4/letter/n/53a042/32.png) [@nnaik](https://forum.inductiveautomation.com/u/nnaik)\
**Post date:** [August 9, 2021, 10:47am UTC](https://forum.inductiveautomation.com/t/help-on-dataset/49690/5 "2021-08-09T10:47:26Z")

</div>

Thanks nminchin, that worked 😃 how did 1 % 2 worked ?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 9, 2021, 10:50am UTC](https://forum.inductiveautomation.com/t/help-on-dataset/49690/6 "2021-08-09T10:50:57Z")

</div>

The modulus takes the remainder of the number on the left integer divided by the number on the right.

```auto
1/2 = 0 remainder 1 so 1 % 2 = 1

```

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [August 9, 2021, 10:52am UTC](https://forum.inductiveautomation.com/t/help-on-dataset/49690/7 "2021-08-09T10:52:33Z")

</div>

in this case %2 return 0 on even and 1 on odd numbers

---

<div class="post-metadata">

**Author:** ![nnaik](https://avatars.discourse-cdn.com/v4/letter/n/53a042/32.png) [@nnaik](https://forum.inductiveautomation.com/u/nnaik)\
**Post date:** [August 9, 2021, 10:53am UTC](https://forum.inductiveautomation.com/t/help-on-dataset/49690/8 "2021-08-09T10:53:12Z")

</div>

I mean, in my code it was updating 1 only in last dataset entry so i was suspecting query was executing only during last (i) entry  
I am aware of modulus function but as mentioned un system.dataset.setdataset script, I was thinking i need to execute though alternate (i) dataset entry and pass 1 as stated in Argument example.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [August 9, 2021, 10:54am UTC](https://forum.inductiveautomation.com/t/help-on-dataset/49690/9 "2021-08-09T10:54:32Z")

</div>

ah break makes you leave the while loop.  
you should have used continue instead

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 9, 2021, 10:55am UTC](https://forum.inductiveautomation.com/t/help-on-dataset/49690/10 "2021-08-09T10:55:53Z")

</div>

Because in your code you were never updating ‘data’ in the while loop, so you were always using the original dataset to set the next value and then writing that over GUI dataset. So the only update you saw was the last.
