# Ignition – Report Module – How to set dynamic the Data Key in a Timeseries chart

**URL:** <https://forum.inductiveautomation.com/t/ignition-report-module-how-to-set-dynamic-the-data-key-in-a-timeseries-chart/106028>\
**Category:** Ignition\
**Tags:** reporting\
**Created:** [May 8, 2025, 9:38am UTC](https://forum.inductiveautomation.com/t/ignition-report-module-how-to-set-dynamic-the-data-key-in-a-timeseries-chart/106028 "2025-05-08T09:38:17Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mushu](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@Mushu](https://forum.inductiveautomation.com/u/Mushu)\
**Post date:** [May 8, 2025, 9:38am UTC](https://forum.inductiveautomation.com/t/ignition-report-module-how-to-set-dynamic-the-data-key-in-a-timeseries-chart/106028/1 "2025-05-08T09:38:17Z")

</div>

Hi,  
We have a report with two query data sources:

1. One is a Named query, that queries three tables.
2. The other query data source is a Script query that uses the rows from the named query result and generates the required datasets with history data for all the relevant tags. The result data sets are named: TagHistory\_x where x is the device number.

In the Design tab there is a table with:

Data Key = Named query data source

With Grouping:

Device

Named query data source

In the Device Details section of the table there is a Timeserieschart that it should show the data from the data set gathered by the script data source, TagHistory\_x

Do you know how to dynamically assign the data set to the Timeserieschart Datakey?

I have tried:

- In the result from the Named query data source there is a column with the Dataset to pick: TagHistory\_x. We can read this field in the table properly using: @DataSet@ (name of the column).
  - @DataSet@ in the Timeserieschart Datakey it doesn’t work
  - DataSet in the Timeserieschart Datakey it doesn’t work

- If I add manually in the Time Series Chart Data Key: TagHistory\_ 1, the chart works

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/3/63672f787801882846655f521c93094c73fb547b.png)

---

<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:** [May 8, 2025, 10:55am UTC](https://forum.inductiveautomation.com/t/ignition-report-module-how-to-set-dynamic-the-data-key-in-a-timeseries-chart/106028/2 "2025-05-08T10:55:49Z")

</div>

> [@Mushu](#):
>
> add manually

You cannot dynamically change the report design's data keys. You **must** cause your queries or script data sources to change any dynamic names in the data to static names that you've pre-configured in the report. You can use visibility in various places if you have a dynamic **number** of keys, and substitute labels as desired. But data keys and column names must be static.

---

<div class="post-metadata">

**Author:** ![Mushu](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@Mushu](https://forum.inductiveautomation.com/u/Mushu)\
**Post date:** [May 8, 2025, 11:35am UTC](https://forum.inductiveautomation.com/t/ignition-report-module-how-to-set-dynamic-the-data-key-in-a-timeseries-chart/106028/3 "2025-05-08T11:35:09Z")

</div>

Thank you Phil.  
I tried:

1. In the Device Details area of the table I added a TextShape (I left it visible. I understand to make it invisible, I just go to Property Inspector \> Property \> Visible unticked) that I called: ThisDeviceDataset and in the text I add: @DataSet@
2. In the Device Details area of the table there is a TimeseriesChart: On the DataKey I write: ThisDeviceDataset
3. The value of @DataSet@ is TagHistory\_1 and so on. The names of the datasets generated by the script query data source  
But it didn’t work for me.  
What did I misunderstand?

---

<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:** [May 8, 2025, 12:31pm UTC](https://forum.inductiveautomation.com/t/ignition-report-module-how-to-set-dynamic-the-data-key-in-a-timeseries-chart/106028/4 "2025-05-08T12:31:11Z")

</div>

You cannot substitute data keys to drive tables or charts. The data keys must be static. Make your script output the static keys you use in the design pane.

---

<div class="post-metadata">

**Author:** ![Mushu](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@Mushu](https://forum.inductiveautomation.com/u/Mushu)\
**Post date:** [May 8, 2025, 1:17pm UTC](https://forum.inductiveautomation.com/t/ignition-report-module-how-to-set-dynamic-the-data-key-in-a-timeseries-chart/106028/5 "2025-05-08T13:17:09Z")

</div>

Thanks again for your reply Phil.

Let me see if I understand:

The Named query data source can retrieve an unknown number of devices.

The Script query data source generates a dataset with history data for each of the devices retrieved by the previous data source.

Example: if the first Data Source retrieves: Device 1, 3 and 5, the second Data Source generates three datasets: TagHistory\_1, TagHistory\_3 and TagHistory\_5.

Does it mean then that:

1. I need to set previously a maximum number of devices that can be handled.  
Say 15. (if it is like this, it would be a problem, as there can be up to 1000 devices)
2. In the Device Details area of the table I must add a TimeseriesChart for each hypothetical device: On the Data Key I should write: TagHistory\_x.  
Following the previous example: 15 TimeseriesCharts, in each TimeseriesChart, the Data key would be TagHistory\_1, TagHistory\_2, TagHistory\_3,…, TagHistory\_15
3. How can the visibility of the TimeseriesChart can be set? So in this way only one of the Timeseries chart would be shown in each of the Device details section.  
Could I set the visibility of the TimeseriesCharts on the Script query data source? I don’t know how it could be done.

---

<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:** [May 8, 2025, 1:32pm UTC](https://forum.inductiveautomation.com/t/ignition-report-module-how-to-set-dynamic-the-data-key-in-a-timeseries-chart/106028/6 "2025-05-08T13:32:58Z")

</div>

OK, not what I thought you were doing. You need nested queries and a table with unstructured rows (to hold the chart).

- Make your outer query retrieve the names and metadata for each device (name, whatever). Call this query `devices`.

- Make your inner query retrieve the tag history for just the one device keyed to the metadata of the outer query. Call this query `taghistory`.

- Tie your table to `@devices@`.

- Tie your timeseries chart to `@taghistory@`. Each row in the table will get the distinct tag history for that device.

---

<div class="post-metadata">

**Author:** ![Mushu](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@Mushu](https://forum.inductiveautomation.com/u/Mushu)\
**Post date:** [May 8, 2025, 1:54pm UTC](https://forum.inductiveautomation.com/t/ignition-report-module-how-to-set-dynamic-the-data-key-in-a-timeseries-chart/106028/7 "2025-05-08T13:54:24Z")

</div>

Thanks again Phil.

I think I comply with the first three points. It is the fourth point where I am struggling. How can I tie the results of the taghistory query to the timeseries chart?

---

<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:** [May 8, 2025, 1:57pm UTC](https://forum.inductiveautomation.com/t/ignition-report-module-how-to-set-dynamic-the-data-key-in-a-timeseries-chart/106028/8 "2025-05-08T13:57:21Z")

</div>

The data key for the timeseries chart should be the name of the **nested** query in your data source.

You data preview XML should show a nested tag history dataset for each row of the devices data key.

---

<div class="post-metadata">

**Author:** ![Mushu](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@Mushu](https://forum.inductiveautomation.com/u/Mushu)\
**Post date:** [May 9, 2025, 8:22am UTC](https://forum.inductiveautomation.com/t/ignition-report-module-how-to-set-dynamic-the-data-key-in-a-timeseries-chart/106028/9 "2025-05-09T08:22:53Z")

</div>

Thank you for your reply Phil. I really appreciate your help.

That was one of the first tries, I had a nested query that it was used as the data key for the timeseries but the result was all the data for all the devices was shown in the timeseries chart.

Fot that reason, my next trial was generating a separate dataset for each device.

What could it be the reason of having all the data together?

How can I preview the data? The way I check if I have data is “print” the data in the logger or “print” the number of data points that I have.

---

<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:** [May 9, 2025, 11:07am UTC](https://forum.inductiveautomation.com/t/ignition-report-module-how-to-set-dynamic-the-data-key-in-a-timeseries-chart/106028/10 "2025-05-09T11:07:33Z")

</div>

Report preview in the designer shows the data in XML format in the right sidebar.

If you are trying to produce **nested** data by **script** , you need to see this old topic:

> [@Report with Scripted Nested Data](https://forum.inductiveautomation.com/t/report-with-scripted-nested-data/11801):
>
> The report datasource scripting examples explain how to access the nested data in another key for use constructing a custom dataset. What I don’t see is how to construct nested data that would be suitable for use with a child table in a table group. I have a parent dataset that I’m constructing via script due to annoying limitations of an ancient SQL Server 2000 instance. I need a subquery for each row that could be done with a normal query, but there’s no way to add a regular subquery to a s…

---

<div class="post-metadata">

**Author:** ![Mushu](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@Mushu](https://forum.inductiveautomation.com/u/Mushu)\
**Post date:** [May 16, 2025, 3:48pm UTC](https://forum.inductiveautomation.com/t/ignition-report-module-how-to-set-dynamic-the-data-key-in-a-timeseries-chart/106028/11 "2025-05-16T15:48:13Z")

</div>

Thank you Phil for your reply.

Following the old topic that you point me out:

- Removed the named query data source.
- Modify the script query data source to generate a nested dataset:

Script\_Batch\_Data[Device, TagPath, Start\_DT\_Local, End\_DT\_Local, DeviceHistData]

Where DeviceHistData is a dataset with these columns: Device, Start\_DT\_Local, End\_DT\_Local, t\_stamp, value.

As I wasn’t sure where Start\_DT\_Local, End\_DT\_Local should be, I have duplicated the data.

I can see the data in data preview XML.

I have the table tied to Script\_Batch\_Data

With Grouping:

Device

Script\_Batch\_Data

In the Device Details section of the table there is a Timeserieschart.

The Timeserieschart is tied to DeviceHistData

Data key = DeviceHistData

Domain Key = DeviceHistData.t\_stamp

Pen

Range Key = DeviceHistData.value

The report fields are working properly. The data is gathered from Script\_Batch\_Data but the Timeserieschart doesn’t show any data.

The date is 1970. But it doesn't show the “No data” message (In my previous trials "No data" was written in the middle of the chart):

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/6/6668871982c945165218463bef7bd37ec67bb10b.png)

I have tried to set the start and end date with a script in the Timeserieschart:

```python
def configureChart(data, chart):

    import system
    from java.util import Calendar

    logger = system.util.getLogger("ReportBatchChart")

    try:
        # --- Try dynamic date assignment from the current row's keys
        startDate = data.get("Start_DT_Local", None)
        endDate = data.get("End_DT_Local", None)

        if startDate and endDate:
            chart.setStartDate(startDate)
            chart.setEndDate(endDate)
            logger.info("Using dynamic start/end: {}, {}".format(startDate, endDate))
        else:
            raise Exception("Start or End date not found in data.")
        #endif
    except:
        # --- Fall back to last 4 hours
        cal = Calendar.getInstance()
        endDate = cal.getTime()
        cal.add(Calendar.HOUR, -4)
        startDate = cal.getTime()

        chart.setStartDate(startDate)
        chart.setEndDate(endDate)
        logger.warn("Fallback: Using hardcoded 4-hour window. Start: {}, End: {}".format(startDate, endDate))
    #endtry

```

But it seems the script is not running (it is set as Enabled) because I don’t get any message in the logger.  
Do you know how could I set the start/end date of the chart?
