# Report data script to exclude negative numbers

**URL:** <https://forum.inductiveautomation.com/t/report-data-script-to-exclude-negative-numbers/63825>\
**Category:** Ignition\
**Tags:** scripting, ignition81, vision\
**Created:** [September 7, 2022, 12:35pm UTC](https://forum.inductiveautomation.com/t/report-data-script-to-exclude-negative-numbers/63825 "2022-09-07T12:35:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![user43](https://avatars.discourse-cdn.com/v4/letter/u/8dc957/32.png) [@user43](https://forum.inductiveautomation.com/u/user43)\
**Post date:** [September 7, 2022, 12:35pm UTC](https://forum.inductiveautomation.com/t/report-data-script-to-exclude-negative-numbers/63825/1 "2022-09-07T12:35:02Z")

</div>

I have a report data script that needs to exclude any values from the database that are negative numbers.

below is the current script.

endTime = system.date.now()  
startTime = system.date.addHours(endTime,-24)

```
tagPaths = ['[IgnitionSQL]abiop_0401_fi',
		'[IgnitionSQL]cbiop_0903_fi',
		'[IgnitionSQL]ips2p_0254_fi',
		'[IgnitionSQL]pspsp_0311_fi',
		'[IgnitionSQL]rwpsp_0621_fi',
		'[IgnitionSQL]rwpsp_0622_fi',
		'[IgnitionSQL]ssubp_0661a_fi',
		'[IgnitionSQL]ssubp_0661b_fi',
		'[IgnitionSQL]ssubp_0662a_fi',
		'[IgnitionSQL]ssubp_0662b_fi',
		'[IgnitionSQL]ssubp_1031_fi',
		'[IgnitionSQL]sdbp_1113_fiq',
		'[IgnitionSQL]sdbp_1114_fiq']
		

data['tagData'] = system.tag.queryTagHistory(paths=tagPaths , returnSize = 24, aggregationMode='SimpleAverage', endDate=endTime, startDate=startTime)

```

Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 7, 2022, 1:06pm UTC](https://forum.inductiveautomation.com/t/report-data-script-to-exclude-negative-numbers/63825/2 "2022-09-07T13:06:46Z")

</div>

`system.tag.queryTagHistory` returns a dataset. After reading the documentation I don’t see any argument you can provide to get this functionality built in, but you can do some manual logic iterating through the dataset.

```auto
ds = system.tag.queryTagHistory(paths=tagPaths , returnSize = 24, aggregationMode='SimpleAverage', endDate=endTime, startDate=startTime)
rowsToDelete = []
for row in range(ds.getRowCount()):
    # do some logic here to determine if the row should be dropped or not - 
    #note that you are getting multiple tag paths per row so you might have 
    # some tags that are negative and others that are positive
    # up to you and your system to figure out what counts as a negative
    if deleteCondition:
        rowsToDelete.append(row)
ds = system.dataset.deleteRows(ds, rowsToDelete)
data['tagData'] = ds

```

Some additional reading about iterating through datasets - [Datasets - Ignition User Manual 8.0 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC80/Datasets)

---

<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:** [September 7, 2022, 3:26pm UTC](https://forum.inductiveautomation.com/t/report-data-script-to-exclude-negative-numbers/63825/3 "2022-09-07T15:26:15Z")

</div>

> [@bkarabinchak.psi](#):
>
> After reading the documentation I don’t see any argument you can provide to get this functionality built in

Officially, you can provide a custom aggregate function, although there are some hurdles to jump through.

[Custom Tag History Aggregates](https://docs.inductiveautomation.com/display/DOC81/Custom+Tag+History+Aggregates)
