# How to display the last 3 values in a column horizontally

**URL:** <https://forum.inductiveautomation.com/t/how-to-display-the-last-3-values-in-a-column-horizontally/65490>\
**Category:** Ignition\
**Tags:** namedqueries, vision\
**Created:** [October 20, 2022, 8:51pm UTC](https://forum.inductiveautomation.com/t/how-to-display-the-last-3-values-in-a-column-horizontally/65490 "2022-10-20T20:51:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brennan\_Joles](https://avatars.discourse-cdn.com/v4/letter/b/d2c977/32.png) [@Brennan\_Joles](https://forum.inductiveautomation.com/u/Brennan_Joles)\
**Post date:** [October 20, 2022, 8:51pm UTC](https://forum.inductiveautomation.com/t/how-to-display-the-last-3-values-in-a-column-horizontally/65490/1 "2022-10-20T20:51:26Z")

</div>

I have the following named query:

```auto
SELECT TOP 3*
FROM
	(SELECT
	 schedOverTimemins as last5,
	 TableNum
	 FROM Tables_Data_East_V2
 	 WHERE TableNum = 5
	) AS SUBQUERYB
	WHERE last5 IS NOT NULL 

```

How would I display these three values in vision horizontally? I know it's probably a simple answer, but I am stuck. I can display them vertically using a table, but I need them to display horizontally.

Thanks

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [October 20, 2022, 9:16pm UTC](https://forum.inductiveautomation.com/t/how-to-display-the-last-3-values-in-a-column-horizontally/65490/2 "2022-10-20T21:16:21Z")

</div>

See if [How to concatenate text from multiple rows into a single text string in SQL Server - Stack Overflow](https://stackoverflow.com/questions/194852/how-to-concatenate-text-from-multiple-rows-into-a-single-text-string-in-sql-serv) helps.

I've never done this and haven't tested it but I think it would be something like,

```auto
SELECT 
    LEFT(Last5, LEN(SUBQUERYC) - 1) AS 'Last5'
FROM
    (SELECT TOP 3*
        FROM
	    (SELECT
	      schedOverTimemins as last5,
	      TableNum
	      FROM Tables_Data_East_V2
 	      WHERE TableNum = 5
	    ) AS SUBQUERYB
	    WHERE last5 IS NOT NULL
    ) SUBQUERYC

```

Alteratively you could use a script transform on your existing result.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [October 20, 2022, 9:53pm UTC](https://forum.inductiveautomation.com/t/how-to-display-the-last-3-values-in-a-column-horizontally/65490/3 "2022-10-20T21:53:34Z")

</div>

> [@Transistor](#):
>
> you could use a script transform

Not in Vision.

---

<div class="post-metadata">

**Author:** ![Brennan\_Joles](https://avatars.discourse-cdn.com/v4/letter/b/d2c977/32.png) [@Brennan\_Joles](https://forum.inductiveautomation.com/u/Brennan_Joles)\
**Post date:** [October 25, 2022, 5:20am UTC](https://forum.inductiveautomation.com/t/how-to-display-the-last-3-values-in-a-column-horizontally/65490/4 "2022-10-25T05:20:00Z")

</div>

Hmm this doesn't seem to work. It states that SUBQUERYC is not a column. Honestly it seems ridiculous that vision doesn't have the option to transpose rows and columns easily or even pull multiple rows into a string.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [October 25, 2022, 6:30am UTC](https://forum.inductiveautomation.com/t/how-to-display-the-last-3-values-in-a-column-horizontally/65490/6 "2022-10-25T06:30:26Z")

</div>

I like the idea of using a simple expression binding to solve this problem. For example, I could add a dataset custom property to the label, and bind the property to my query. See the example below:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/0/100806900185c1b139177eb41eeb00d85b5c71e6.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/c/5cfb427b2d854542f2e65011fadc06b64a2a7e16.png)

Once I have the data in the label's custom property, I can display the data by applying an expression binding to the **text property** of the label:

```auto
try({Root Container.Label.data}[0,0],"")+ ", "
+try({Root Container.Label.data}[1,0],"")+ ", "
+try({Root Container.Label.data}[2,0],"")

```

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

**The preceding expression produces the following result:**  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/9/199221bd9fa222e5653f3e3cc4101e9d1806fe4b.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:** [October 25, 2022, 12:42pm UTC](https://forum.inductiveautomation.com/t/how-to-display-the-last-3-values-in-a-column-horizontally/65490/7 "2022-10-25T12:42:28Z")

</div>

> [@Brennan\_Joles](#):
>
> Honestly it seems ridiculous that vision doesn't have the option to transpose rows and columns easily or even pull multiple rows into a string.

Well, Vision may not have script transforms built into the binding window, but you can get the effect of that by using `runScript()` or my `objectScript()` in an expression binding. Such a script can perform whatever transpose operation you like. This solution predates Perspective:

> [@Transpose Rows and Columns](https://forum.inductiveautomation.com/t/transpose-rows-and-columns/14308/2):
>
> I have something that could be massaged into what you need. The follow code is designed to take one or more datasets, each with a just a few rows, and flip all the rows into columns. Should be close to what you need: #---------- # Construct a dataset with columns from supplied datasets rows. The column # names from the first dataset become the string values in the first column # of the result. The first argument to the function is a sequence of names # for the dataset arguments. The name s…

You might also find the Pseudo-SQL PIVOT from my `view()` expression function useful.

{ `objectScript()` and `view()` are from my free [Simulation Aids Module](https://inductiveautomation.com/moduleshowcase/module/automation-professionals-llc-simulation-aids). }

---

<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:** [October 25, 2022, 3:30pm UTC](https://forum.inductiveautomation.com/t/how-to-display-the-last-3-values-in-a-column-horizontally/65490/8 "2022-10-25T15:30:59Z")

</div>

> [@Brennan\_Joles](#):
>
> even pull multiple rows into a string.

`groupConcat`:  
[https://docs.inductiveautomation.com/display/DOC81/groupConcat](https://docs.inductiveautomation.com/display/DOC81/groupConcat)  
Works (on datasets) in ~every Ignition version you're likely to come across.
