# Auto pull historical data from the tag historian to ignition at certain times

**URL:** <https://forum.inductiveautomation.com/t/auto-pull-historical-data-from-the-tag-historian-to-ignition-at-certain-times/27641>\
**Category:** Ignition\
**Created:** [August 21, 2019, 6:41pm UTC](https://forum.inductiveautomation.com/t/auto-pull-historical-data-from-the-tag-historian-to-ignition-at-certain-times/27641 "2019-08-21T18:41:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jparsons](https://avatars.discourse-cdn.com/v4/letter/j/ea666f/32.png) [@jparsons](https://forum.inductiveautomation.com/u/jparsons)\
**Post date:** [August 21, 2019, 6:41pm UTC](https://forum.inductiveautomation.com/t/auto-pull-historical-data-from-the-tag-historian-to-ignition-at-certain-times/27641/1 "2019-08-21T18:41:58Z")

</div>

Hello, I am wanting to pull all of the data for 3 tags from my tag historian to an excel sheet every sunday night. The data comes in at 5 minute increments. I know that I am missing something easy. I looked around and could find things that were close to what I was wanting but nothing was just right. If anyone could help that would be great!

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [August 21, 2019, 6:59pm UTC](https://forum.inductiveautomation.com/t/auto-pull-historical-data-from-the-tag-historian-to-ignition-at-certain-times/27641/2 "2019-08-21T18:59:00Z")

</div>

There are a few ways to do this. One way would be to have an express tag like so

```auto
if(dateFormat(now(0), "E") = "Sun" && dateFormat(now(0), "HH:mm") = "22:30", 1, 0)

```

On the tag’s **valueChange** event put your code to run your logic

```auto
if currentValue.value == 1:
    script to run

```

---

<div class="post-metadata">

**Author:** ![jparsons](https://avatars.discourse-cdn.com/v4/letter/j/ea666f/32.png) [@jparsons](https://forum.inductiveautomation.com/u/jparsons)\
**Post date:** [August 21, 2019, 8:55pm UTC](https://forum.inductiveautomation.com/t/auto-pull-historical-data-from-the-tag-historian-to-ignition-at-certain-times/27641/4 "2019-08-21T20:55:08Z")

</div>

That works thank you! I think I figured out how to pull it to excel also.

I found this:

Create a variable that references our Power Table. You could modify this part  
of the example to point to a different component in the window.

component = event.source.parent.getComponent(‘Table’)

Use system.dataset.toCSV to turn the dataset into a CSV string

csv = system.dataset.toCSV(component.data)

Write to local file system. Note the “r” character right before the directory path.  
This denotes a raw string literal, meaning we ignore escape sequences (like the “/”)

system.file.writeFile(r"filepath/xxxx.csv", csv)
