# Group by on a Dataset

**URL:** <https://forum.inductiveautomation.com/t/group-by-on-a-dataset/37728>\
**Category:** Ignition\
**Tags:** ignition80, scripting\
**Created:** [August 14, 2020, 2:51pm UTC](https://forum.inductiveautomation.com/t/group-by-on-a-dataset/37728 "2020-08-14T14:51:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![LopezSilvanoE](https://avatars.discourse-cdn.com/v4/letter/l/82dd89/32.png) [@LopezSilvanoE](https://forum.inductiveautomation.com/u/LopezSilvanoE)\
**Post date:** [August 14, 2020, 2:51pm UTC](https://forum.inductiveautomation.com/t/group-by-on-a-dataset/37728/1 "2020-08-14T14:51:11Z")

</div>

Hi hello.

I have a issue regarding to the dataset obtained from a Tag History.

Im using this script:

endTime =event.source.parent.getComponent(‘Date Range’).endDate  
startTime = event.source.parent.getComponent(‘Date Range’).startDate

data = system.tag.queryTagHistory(paths=["[default]L7/PNT/AlarmsMonitor/TransactionGroups/Spur05/Trigger\_Spur05"], startDate=startTime, endDate=endTime , returnSize=0, aggregationMode = “Count”, columnNames = [“TimeStamp”, “Count”])

formattedData = system.dataset.formatDates(data, “HH:00”)  
event.source.parent.getComponent(‘Power Table 1’).data = formattedData

The Information display like this:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/e/aefc8e0e4021974dbd3ad4a8052f76b77acf09b8.png)

Dataset Obtained form the TagHistory:  
TimeStamp|Count|  
|06:00|0|  
|07:00|1|  
|07:00|0|  
|07:00|1|  
|07:00|0|  
|07:00|1|  
|07:00|0|  
|08:00|1|  
|08:00|0|  
|08:00|1|  
|08:00|0|  
|10:00|1|  
|10:00|0|  
|10:00|1|  
|10:00|0|  
|10:00|1|  
|10:00|0|  
|12:00|1|  
|12:00|0|  
|12:00|1|  
|12:00|0|  
|12:00|1|  
|12:00|0|

Exists a script to group the dataset information by TimeStamp, and count all the number “1” on the column Count, just like the same Functtion “group by” that we use on SQL query.  
“Example:”  
TimeStamp|Count|  
|07:00|5|  
|08:00|2|  
|09:00|10|

Thanks for your help and sharing knowledge

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [August 14, 2020, 2:57pm UTC](https://forum.inductiveautomation.com/t/group-by-on-a-dataset/37728/2 "2020-08-14T14:57:33Z")

</div>

You might get what you want by using intervalHours=1 as an argument in queryTagHistory. If you do that I’m not sure you need returnSize.

---

<div class="post-metadata">

**Author:** ![LopezSilvanoE](https://avatars.discourse-cdn.com/v4/letter/l/82dd89/32.png) [@LopezSilvanoE](https://forum.inductiveautomation.com/u/LopezSilvanoE)\
**Post date:** [August 14, 2020, 7:10pm UTC](https://forum.inductiveautomation.com/t/group-by-on-a-dataset/37728/3 "2020-08-14T19:10:16Z")

</div>

> [@zacht](#):
>
> intervalHours

Thanks My friend . it woks.

This is the script:

endTime =event.source.parent.getComponent('Date Range').endDate  
startTime = event.source.parent.getComponent('Date Range').startDate

data = system.tag.queryTagHistory(paths=["[default]L7/PNT/AlarmsMonitor/TransactionGroups/Spur05/Trigger\_Spur05"], startDate=startTime, endDate=endTime, aggregationMode = "Count", columnNames = ["TimeStamp", "Count"], **intervalHours = 1** )

formattedData = system.dataset.formatDates(data, "HH:00")  
event.source.parent.getComponent('Power Table 1').data = formattedData

And the data will look like this:

 ![Dataset2](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/4/a4252e5ac2c87f0cc290dfbd66f6b6575d3809e1.png)

Thanks for your time.

Regrads

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [August 14, 2020, 7:11pm UTC](https://forum.inductiveautomation.com/t/group-by-on-a-dataset/37728/4 "2020-08-14T19:11:46Z")

</div>

I’m glad it works. It’s nice when there’s easy fixes!
