# Reporting: Nesting Data For A Time Series Chart

**URL:** <https://forum.inductiveautomation.com/t/reporting-nesting-data-for-a-time-series-chart/12164>\
**Category:** Ignition\
**Created:** [September 25, 2016, 12:07am UTC](https://forum.inductiveautomation.com/t/reporting-nesting-data-for-a-time-series-chart/12164 "2016-09-25T00:07:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![WildeKurt](https://avatars.discourse-cdn.com/v4/letter/w/50afbb/32.png) [@WildeKurt](https://forum.inductiveautomation.com/u/WildeKurt)\
**Post date:** [September 25, 2016, 12:07am UTC](https://forum.inductiveautomation.com/t/reporting-nesting-data-for-a-time-series-chart/12164/1 "2016-09-25T00:07:35Z")

</div>

I’d like to use a time series chart inside a table in a similar way one would nest a query inside another. However I need the tags that I’ll be displaying to be dynamic and selected as part of another query. I can do this in script and use system.tag.queryTagHistory() to get the appropriate dataset. However I can only get it to work with a single historical dataset, where I need multiple (the exact number would vary depending on the parent query). Is there a way to produce the same kind of datsets that result from a nested query? In script, I’ve tried various combinations of lists, dictionaries, datasets, etc. none of which seem to work. In the report designer it looks like a nested query produces a dataset inside a dataset but of course if I try to do that in script it bombs. Any help would be appreciated.

---

<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:** [September 25, 2016, 2:28am UTC](https://forum.inductiveautomation.com/t/reporting-nesting-data-for-a-time-series-chart/12164/2 "2016-09-25T02:28:24Z")

</div>

[This topic](https://inductiveautomation.com/forum/viewtopic.php?f=94&t=15773) might help you.

---

<div class="post-metadata">

**Author:** ![WildeKurt](https://avatars.discourse-cdn.com/v4/letter/w/50afbb/32.png) [@WildeKurt](https://forum.inductiveautomation.com/u/WildeKurt)\
**Post date:** [September 26, 2016, 7:29pm UTC](https://forum.inductiveautomation.com/t/reporting-nesting-data-for-a-time-series-chart/12164/3 "2016-09-26T19:29:45Z")

</div>

Very helpful. I used system.tag.queryTagHistory() for the child query and it works just fine. The inner query bit ended up looking like this:

`	for r in range(parentds.rowCount):
		# Use parentds.getValueAt(r, 'some ref column') to retrieve foreign key(s)
		sel = "SELECT asset,facility,fullPath,label FROM rpt_tankBatteryLevelTrend_view WHERE facility = ?"
		facilityName = parentds.getValueAt(r,"name")	
		args = [facilityName]			
		pds = system.db.runPrepQuery(sel,args,"SQLSERVER")
		tps = [x["fullPath"] for x in pds]
		hdrs = [str(x["label"]) for x in pds] 
		startDate = data["StartDate"]
		endDate = data["EndDate"]
		colNames = ["t_stamp"] + hdrs 
		h = system.tag.queryTagHistory(paths=tps,returnFormat="Wide",columnNames=colNames,intervalMinutes=5,startDate=startDate,endDate=endDate,ignoreBadQuality=True)
		# for each data column, another one exists that's always true (used to evaluate for key visibility on the chart)
		col = [True] * h.rowCount
		for c in hdrs:
			h = system.dataset.addColumn(h,col,c + 'Show',bool)
		childList.append(QueryResults(h, parentqr, r))
		for itm in fullSet:
			if itm in hdrs:
				penKeyRows.append([itm,True])
			else:
				penKeyRows.append([itm,False])`

I added additional columns to control the visibility of the pen key on the chart as the returned dataset has a variable number of pens (columns) up to 16.
