# Reporting - Dynamic Historical Tags

**URL:** <https://forum.inductiveautomation.com/t/reporting-dynamic-historical-tags/18435>\
**Category:** Ignition\
**Tags:** scripting, database, ignition79\
**Created:** [June 13, 2018, 12:40am UTC](https://forum.inductiveautomation.com/t/reporting-dynamic-historical-tags/18435 "2018-06-13T00:40:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cesrom](https://avatars.discourse-cdn.com/v4/letter/c/ea666f/32.png) [@cesrom](https://forum.inductiveautomation.com/u/cesrom)\
**Post date:** [June 13, 2018, 12:40am UTC](https://forum.inductiveautomation.com/t/reporting-dynamic-historical-tags/18435/1 "2018-06-13T00:40:37Z")

</div>

Searching the online documentation I found that you may have pseudo-dynamic historical tags configured for your [Tag Historian Query](https://docs.inductiveautomation.com/display/DOC79/Tag+Historian+Query) on your reports. And I say **pseudo** because a fixed set of tags must be configured.

This works when all of the devices share the same set of tags, but what if they don’t? What to do then?

Take this for example:

```auto
Ovens
  - Oven 1
    - Z1
  - Oven 2
    - Z1
    - Z2
  - Oven 3
    - Z1
    - Z2
    - Z3

```

If I created a single report and use indirection (as suggested in the docs), I would have to manually create three tags and replace the oven number with a parameter I’d bind to the report. But this would mean that Ovens 1, and 2 would show tags that don’t even exist for them (Z2, and Z3 for Oven 1, and Z3 for Oven 2).

Does this mean that I definitely have no other choice but to create a report for each oven? 😓

* * *

On the other hand, I’ve been considering manually querying historical information from the database, retrieving data from two tables as needed (in case I am using monthly partitions, and wanted to retrieve data from the final days of one month, and the first day of the subsequent month), and plot that onto the XY Chart. But then, how to format the date values on the X axis from “Epoch” onto human-readable dates?

Thoughts anyone?

Thanks!

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 13, 2018, 2:59pm UTC](https://forum.inductiveautomation.com/t/reporting-dynamic-historical-tags/18435/2 "2018-06-13T14:59:48Z")

</div>

You can use a scripting datasource (even a nested one) to perform your tag history query in a dynamic way and nest the results.

---

<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:** [June 13, 2018, 3:13pm UTC](https://forum.inductiveautomation.com/t/reporting-dynamic-historical-tags/18435/3 "2018-06-13T15:13:20Z")

</div>

> [@paul-griffith](#):
>
> (even a nested one)

See this topic for ideas:

> [@Report with Scripted Nested Data](http://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:** ![cesrom](https://avatars.discourse-cdn.com/v4/letter/c/ea666f/32.png) [@cesrom](https://forum.inductiveautomation.com/u/cesrom)\
**Post date:** [June 13, 2018, 7:54pm UTC](https://forum.inductiveautomation.com/t/reporting-dynamic-historical-tags/18435/4 "2018-06-13T19:54:09Z")

</div>

I guess I forgot to mention that I intend to plot the historical data onto a Timeseries Chart.

I am thinking about using [system.tag.queryTagHistory](https://docs.inductiveautomation.com/display/DOC79/system.tag.queryTagHistory) on my Script Data Source. But the Pens on any charting component appear to be static (or pseudo-dynamic).

I’m not able to dynamically bind pens to any of them. Unless I am missing something or maybe Ignition does not currently offer a way to handle this scenario.

Could I bind the Pens via the configureChart function?

Or is my approach not the most appropriate?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 13, 2018, 8:07pm UTC](https://forum.inductiveautomation.com/t/reporting-dynamic-historical-tags/18435/5 "2018-06-13T20:07:47Z")

</div>

The actual pens are static, but as of 7.9.7 the `configureChart` function does have access to the other datasources on the report - so it _would_ be possible to manually bridge between Ignition datasets and JFree datasets. Not trivial, but possible.

---

<div class="post-metadata">

**Author:** ![cesrom](https://avatars.discourse-cdn.com/v4/letter/c/ea666f/32.png) [@cesrom](https://forum.inductiveautomation.com/u/cesrom)\
**Post date:** [June 13, 2018, 8:23pm UTC](https://forum.inductiveautomation.com/t/reporting-dynamic-historical-tags/18435/6 "2018-06-13T20:23:00Z")

</div>

Due to time constraints I guess my only option is creating individual reports, but this is something that I will add on the ideas portal.

Thank you all for your input.

---

<div class="post-metadata">

**Author:** ![tordvd](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tordvd/32/11525_2.png) [@tordvd](https://forum.inductiveautomation.com/u/tordvd)\
**Post date:** [March 18, 2021, 8:33am UTC](https://forum.inductiveautomation.com/t/reporting-dynamic-historical-tags/18435/7 "2021-03-18T08:33:41Z")

</div>

This will create a dynamic timeseries chart, given that all possible pens are pre-defined. (legend items for pens not used will be hidden):

> [@Dynamic report chart, legend not hiding unused pens](http://forum.inductiveautomation.com/t/dynamic-report-chart-legend-not-hiding-unused-pens/44565/3):
>
> Thank you this worked! The reporting timeseries chart can now support a dynamic dataset. A short how to for the next guy: Define the maximum amount of pens your chart will have. Edit the chart-script according to the code below. Populate your chart like you normally do. Just make sure that your pen labels for the chart are the same as your dataset(datasource) column labels. This is used to match which labels to hide. See screenshot below: Code for hiding legend items not used: f…
