# Report headers lookup

**URL:** <https://forum.inductiveautomation.com/t/report-headers-lookup/10694>\
**Category:** General Discussion\
**Created:** [October 29, 2015, 3:40pm UTC](https://forum.inductiveautomation.com/t/report-headers-lookup/10694 "2015-10-29T15:40:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pgmo](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@pgmo](https://forum.inductiveautomation.com/u/pgmo)\
**Post date:** [October 29, 2015, 3:40pm UTC](https://forum.inductiveautomation.com/t/report-headers-lookup/10694/1 "2015-10-29T15:40:50Z")

</div>

I’m using Ignition 7.8.0 reporting module.  
I need to develop a crosstab report like in the following picture

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/7/71dfc997505dc6ed5e75f2f295ee67fbd8524c6b.JPG)

Each column header represents a component, whose numeric code is coming from the query. Is there any lookup function that could substitue the component numeric code with its name?

Thank you in advance,  
regards

---

<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:** [October 29, 2015, 3:56pm UTC](https://forum.inductiveautomation.com/t/report-headers-lookup/10694/2 "2015-10-29T15:56:36Z")

</div>

How are you generating that data now? You might be able to join the source data with a table of names vs. IDs, then pivot on the name.

---

<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:** [October 29, 2015, 6:49pm UTC](https://forum.inductiveautomation.com/t/report-headers-lookup/10694/3 "2015-10-29T18:49:38Z")

</div>

I was going to suggest trying the PIVOT functionality of the view() function in my [Simulation Aids](http://marketplace.inductiveautomation.com/moduledetail?moduleId=93) module, but I remembered that the view() function was available only in client or designer scope. That was based on the fact that gateway tags couldn’t be datasets . . . which is no longer true in v7.8. 😃  
So, I perused the code and it looks like it should just work™. I made that one change and uploaded to the marketplace today 🙂  
You might find it useful for this problem. Examples showing the use of the PIVOT clause are embedded in the demo project for this module, found at the bottom of [this thread](https://inductiveautomation.com/forum/viewtopic.php?f=50&t=14532).

---

<div class="post-metadata">

**Author:** ![pgmo](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@pgmo](https://forum.inductiveautomation.com/u/pgmo)\
**Post date:** [October 30, 2015, 10:06am UTC](https://forum.inductiveautomation.com/t/report-headers-lookup/10694/4 "2015-10-30T10:06:58Z")

</div>

> [@pturmel](#):
>
> How are you generating that data now? You might be able to join the source data with a table of names vs. IDs, then pivot on the name.

Thank you pturmel. I generate my data in a MS SQL Server stored procedure: hence I chose to generate my PIVOTed data with the PIVOT T-SQL statement and let Ignition show the data through a simple table.  
My decision is also due to some wrong calculations made by the crosstab object: sometimes the \<N/A\> row (please refer to my previous screenshot) appears as a row with a value of 1 as row header (instead of \<N/A\>, which is correct, because some unpivoted values are NULL) and the corresponding values are all 0 (the screenshot shows the correct values, i.e. a 23 for component 2 and a 1 for component 13).

---

<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:** [October 30, 2015, 12:00pm UTC](https://forum.inductiveautomation.com/t/report-headers-lookup/10694/5 "2015-10-30T12:00:06Z")

</div>

[quote=“pgmo”]I chose to generate my PIVOTed data with the PIVOT T-SQL statement and let Ignition show the data through a simple table.[/quote]Ok. So T-SQL can join the names before pivoting. If you share your T-SQL, I may be able to help you with that.[quote=“pgmo”]My decision is also due to some wrong calculations made by the crosstab object[/quote]Which crosstab object are you referring to? Results from my view() function? If so, I’d love to have a sample to use to fix it.

---

<div class="post-metadata">

**Author:** ![pgmo](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@pgmo](https://forum.inductiveautomation.com/u/pgmo)\
**Post date:** [October 30, 2015, 12:12pm UTC](https://forum.inductiveautomation.com/t/report-headers-lookup/10694/6 "2015-10-30T12:12:46Z")

</div>

> [@pturmel](#):
>
> Which crosstab object are you referring to? Results from my view() function? If so, I'd love to have a sample to use to fix it.

Don't worry pturmel, I mean the Ignition crosstab object which I first used to generate the attached table:  
 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/7/71dfc997505dc6ed5e75f2f295ee67fbd8524c6b.JPG)  
  
You can see here, there is a row header \<N/A\>, which is correct (I have some "general" stuff in the table that carry no StepNr: the field StepNr for that stuff is NULL - I'll filter it out): switching between the report editor and the preview pane, instead of \<N/A\> randomly it shows 1 and the associated values on the row are all 0 (the query behind is a simple SELECT, no T-SQL calculation, no pre-PIVOTING, a very simple SELECT on a normalized table: StepNr | ComponentID | Quantity).

---

<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:** [October 30, 2015, 12:44pm UTC](https://forum.inductiveautomation.com/t/report-headers-lookup/10694/7 "2015-10-30T12:44:24Z")

</div>

> [@pgmo](#):
>
> the query behind is a simple SELECT, no T-SQL calculation, no pre-PIVOTING, a very simple SELECT on a normalized table: StepNr | ComponentID | Quantity).

Ok. So make a table (if you don't already have one) that has ComponentID & ComponentName columns, join it, and select the name instead of the ID. Then the crosstab will have the right raw data. Something like:`Select StepNr, ComponentName, Quantity
From stepqty Inner Join Components On stepqty.ComponentID=Components.ComponentID
Where StepNr Is Not Null;`
