# Exporting Data to CSV

**URL:** <https://forum.inductiveautomation.com/t/exporting-data-to-csv/88140>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [April 1, 2024, 10:04am UTC](https://forum.inductiveautomation.com/t/exporting-data-to-csv/88140 "2024-04-01T10:04:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hive121](https://avatars.discourse-cdn.com/v4/letter/h/90ced4/32.png) [@hive121](https://forum.inductiveautomation.com/u/hive121)\
**Post date:** [April 1, 2024, 10:04am UTC](https://forum.inductiveautomation.com/t/exporting-data-to-csv/88140/1 "2024-04-01T10:04:04Z")

</div>

Hello,

I am using Ignition Perspective and I have built a page which allows you to:

1- select a tag from "TagBrowseTree'  
2- select the start time  
3- select the end time  
4- click export button

The export button has the following OnClick Event:

```auto
def runAction(self, event):
	# Assuming you have a Tag Browser component named 'TagBrowser' and start/end time input components
	
	# Get selected tags from the Tag Browser
	selectedTags = self.getSibling("TagBrowseTree").props.selection.values
	
	# Get start and end times from input components (replace 'startTime' and 'endTime' with your actual component names)
	startTime = self.getSibling("startTime").props.value
	endTime = self.getSibling("endTime").props.value
	
	# Query historical data for selected tags within the specified time range
	historicalData = system.tag.queryTagHistory(paths=selectedTags, startDate=startTime, endDate=endTime)
	
	csv = system.dataset.toCSV(historicalData)
	
	# Use system.file.saveFile to have the user find a directory to write to.
	filePath = system.perspective.download("TrendExport.csv", csv, "Comma Separated Values")

```

I have noticed that when I click on the export button and the tag selected is of type float, the csv table duplicates the last value with the timestamp I clicked on the export button. Refer to images below.  
I do not have this issue with non-float values such as datetime or string. How can I make sure that float values do get the duplicate? I just want what is stored in the database to be exported.

Notice the timestamp is 2:42:58 AM

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/7/37fd6566fdaf9d5e2c372caaaa3228859fb15f65.png)

When I clicked the export button at 2:44:05 AM, this is what I got in my csv file but the timestamp of the tag did not really change:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/1/91a663194b8e5ee5a737b541643aa03cb51bf0ec.png)

---

<div class="post-metadata">

**Author:** ![hive121](https://avatars.discourse-cdn.com/v4/letter/h/90ced4/32.png) [@hive121](https://forum.inductiveautomation.com/u/hive121)\
**Post date:** [April 1, 2024, 10:59am UTC](https://forum.inductiveautomation.com/t/exporting-data-to-csv/88140/2 "2024-04-01T10:59:35Z")

</div>

I did some more testing with a datetime tag and a string tag. I got the following results when I selected both tags and exported to CSV:

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/9/193f7fcd3760e49c4b5218a2c970da1934f68cf1.png)

In my database, I have only 1 record for "Operator Initials" at the following timestamp:

- 2:31:20 AM

And I have 4 records for "Sample Date and Time" at the following timestamps:

- 2:21:32 AM
- 2:24:08 AM
- 2:31:20 AM
- 2:35:55 AM

At the end, I want to export a csv which contains data from multiple tags and only shows values which are in the database. In the example above, I do not have a record in my database for "Operator Initials" at 2:35:55 AM so why is it showing up in the spreadsheet?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 1, 2024, 11:16am UTC](https://forum.inductiveautomation.com/t/exporting-data-to-csv/88140/3 "2024-04-01T11:16:38Z")

</div>

This looks related to your other question over here:

> [@Tags not storing if value is not changing](https://forum.inductiveautomation.com/t/tags-not-storing-if-value-is-not-changing/88141):
>
> Hello, I am using Ignition Perspective and I have created a page where operators can enter some notes, their initials, and a datetime as shown below: [image] When the "Add" button is clicked, the values entered by the operator are written to tags via system.tag.writeBlocking The historian of the tags are enabled which stores the values into a database. I am using this page as a log and would like that every time the operator clicks the add button a new entry is stored in the database (even i…

The simple answer is that you are using the tag historian for a task for which it is not designed. Every value it stores is "solitary", with its own timestamp, and not associated with any other.

You are trying to make Ignition's historian behave like a plain database, and that won't work. Use a plain database table, to which you insert rows from your user interface.
