# Help with reducing my queries per page on a dashboard

**URL:** <https://forum.inductiveautomation.com/t/help-with-reducing-my-queries-per-page-on-a-dashboard/79514>\
**Category:** Ignition\
**Created:** [September 22, 2023, 4:06pm UTC](https://forum.inductiveautomation.com/t/help-with-reducing-my-queries-per-page-on-a-dashboard/79514 "2023-09-22T16:06:30Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [September 22, 2023, 4:06pm UTC](https://forum.inductiveautomation.com/t/help-with-reducing-my-queries-per-page-on-a-dashboard/79514/1 "2023-09-22T16:06:31Z")

</div>

I am on 8.1.19 version.

If I had a hundred queries on a page and I wanted to replace them with just 1 query, what would be the best way to distribute the information to labels?

My idea right now is to make custom properties on my view from the query.  
I want to make 12 cards of data per production line.  
My query has 12 rows of 20 columns.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 22, 2023, 4:15pm UTC](https://forum.inductiveautomation.com/t/help-with-reducing-my-queries-per-page-on-a-dashboard/79514/2 "2023-09-22T16:15:57Z")

</div>

I assume you have a query per card right now? What's your current setup like? Typically when I grab data from a dataset to a component, I make a custom property on the component I call `initialValue` which is an expression of the sort `try({Root Container.initalData}[0, 'someColumn'], 'someDefaultValue')`. I would imagine and hope this translates fine to perspective.

You may be able to combine the queries or you may not but it's hard to tell without more information. If they're all selecting the same columns with slightly different where clauses like  
`SELECT someColumn FROM table WHERE card=1` and then `SELECT someColumn FROM table WHERE card=2` you can combine them with a UNION to convert all these into one

```auto
SELECT someColumn FROM table WHERE card=1
UNION
SELECT someColumn FROM table WHERE card=2
etc

```

And then the `try` statement would need to reference the correct row, not just `0` in this part `[0, 'someColumn']`.

If the queries are all using the same where clause and are just selecting different columns, or each component is doing a SELECT on a single column with the same where clause, I would definitely combine those into a single query and extract with an expression.

Again though I think we'll need more info on your current setup to give better feedback.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [September 22, 2023, 4:27pm UTC](https://forum.inductiveautomation.com/t/help-with-reducing-my-queries-per-page-on-a-dashboard/79514/3 "2023-09-22T16:27:35Z")

</div>

I think I could just be done if this function existed:  
`data.getRowIndex(rowName)`

I have exactly one query on my view custom property.  
I don't know how to just get the speed of my B2 line from the query to my labels.

All the dataset functions are setup for getting column information.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 22, 2023, 4:30pm UTC](https://forum.inductiveautomation.com/t/help-with-reducing-my-queries-per-page-on-a-dashboard/79514/4 "2023-09-22T16:30:12Z")

</div>

If your view only has one query, I don't think you can reduce it anymore without the view becoming meaningless.

Is your actual issue is how fast your components populate from said dataset?

Is the query slow? Have you run an explain statement and indexed appropriate columns

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [September 22, 2023, 4:33pm UTC](https://forum.inductiveautomation.com/t/help-with-reducing-my-queries-per-page-on-a-dashboard/79514/5 "2023-09-22T16:33:57Z")

</div>

My issue is there aren't any row functions for datasets.

So I don't know how to get data out of my dataset.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 22, 2023, 4:35pm UTC](https://forum.inductiveautomation.com/t/help-with-reducing-my-queries-per-page-on-a-dashboard/79514/6 "2023-09-22T16:35:39Z")

</div>

Is your setup your dataset set has 12 rows and you're trying to get one row for each card, row 0 for card 1, row 1 for card 2, etc?

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [September 22, 2023, 4:38pm UTC](https://forum.inductiveautomation.com/t/help-with-reducing-my-queries-per-page-on-a-dashboard/79514/7 "2023-09-22T16:38:53Z")

</div>

Great question.

I think that is what I want to do.  
I don't know how to just get that row where I have data for line 'B2' though for example.

In the past, I pulled data out with the column functions.  
I just have no idea how to get row data out though.

The only examples I saw use view(), and I don't see that in the expression functions.  
I don't know where that comes from. Only throws errors for me.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 22, 2023, 4:46pm UTC](https://forum.inductiveautomation.com/t/help-with-reducing-my-queries-per-page-on-a-dashboard/79514/8 "2023-09-22T16:46:13Z")

</div>

That is from @pturmel 's Simulation Aids which is a module I do highly recommend, it's free, and I think it would make your situation much more manageable with an expression.

You could do something like this

```auto
ds = system.dataset.toDataSet(system.db.runQuery("SELECT * FROM someTable"))

def getRow(ds, rowInd):
       # if you want it as a basic dataset, otherwise just system.dataset.toPyDataSet(ds)[rowInd] for pyDS
	return system.dataset.toDataSet(list(ds.columnNames), [system.dataset.toPyDataSet(ds)[rowInd]])

rowData = getRow(ds, 0)

```

to get the row out of a ds as a dataset, but I doubt it would be as performant as downloading the Simulation Aid's module and using `view`.

My personal opinion is if you can install the module, just do it. It will make all your dataset manipulations much easier to handle via expressions.

Not for nothing either, but if this system/perspective app is only going to be used by a single person or a handful of people, 12 queries isn't a lot nor should it take a lot of time on a well indexed table where you're selecting based on the primary key, and if that is the case, I would probably just be doing the query inside of each card view, and providing the primary key as a parameter. I would only bother trying to reduce the query here if I knew for a fact a ton of people were going to use it, or people started complaining of slowness.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [September 22, 2023, 5:19pm UTC](https://forum.inductiveautomation.com/t/help-with-reducing-my-queries-per-page-on-a-dashboard/79514/9 "2023-09-22T17:19:10Z")

</div>

I do this by having my query in a tag, then have one expression tag per row using `lookup()`. Do note that my queries only return a few dozen rows or less.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [September 22, 2023, 5:38pm UTC](https://forum.inductiveautomation.com/t/help-with-reducing-my-queries-per-page-on-a-dashboard/79514/10 "2023-09-22T17:38:57Z")

</div>

Could you show me how to use lookup to get a row?

I have not had success with it.

---

<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 22, 2023, 6:22pm UTC](https://forum.inductiveautomation.com/t/help-with-reducing-my-queries-per-page-on-a-dashboard/79514/11 "2023-09-22T18:22:11Z")

</div>

Create a sample dataset for us, by hand if necessary, sanitizing any private information. Copy the dataset to the clipboard, and paste it here like you would for code. Then show us what results you want picked out of it for your application.

Keep in mind that Ignition's expression language natively supports picking out values from a dataset by row index and by column (index or name).

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [September 22, 2023, 6:39pm UTC](https://forum.inductiveautomation.com/t/help-with-reducing-my-queries-per-page-on-a-dashboard/79514/12 "2023-09-22T18:39:31Z")

</div>

I will post it.

I have been put on a different thing, but I will post asap.

---

<div class="post-metadata">

**Author:** ![Felipe\_CRM](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Felipe\_CRM](https://forum.inductiveautomation.com/u/Felipe_CRM)\
**Post date:** [September 22, 2023, 6:43pm UTC](https://forum.inductiveautomation.com/t/help-with-reducing-my-queries-per-page-on-a-dashboard/79514/13 "2023-09-22T18:43:11Z")

</div>

> [@zacharyw.larson](#):
>
> I want to make 12 cards of data per production line.  
> My query has 12 rows of 20 columns.

Do you mean each production line has 12 cards with one value each, so you have 20 production lines with 12 values per column? Or that each card is a production line, so each production line is 1 row in your data set?

The second is usually more common, so I'll make that assumption for starters. Correct me if it's wrong.

If you have a column (e.g. 'Name') with the name of each line, and a column of values (e.g. 'Speed'), then you can use the `lookup` function to get the speed of line B2 as follows:

```auto
lookup({data}, "B2", 0, "Name", "Speed")

```

that is, check "Name" column for "B2" and return the value of "Speed" in that row, and return 0 if nothing found.

> **Line per column case**
>
> If you have the second case where each production line is its own column, then I hope you have an extra column with the type of info labeled (e.g. "InfoType", in which case it would be
> 
> ```auto
> lookup({data}, "Speed", 0, "InfoType", "B2")
> 
> ```
> 
> that is, check "InfoType" column for "Speed" and return the value of "B2" in that row.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [September 25, 2023, 1:45pm UTC](https://forum.inductiveautomation.com/t/help-with-reducing-my-queries-per-page-on-a-dashboard/79514/14 "2023-09-25T13:45:31Z")

</div>

`lookup({data}, "B2", 0.0, "LineName", "Speed")`

Thanks very much.

I think two view custom property query bindings updating every 30 seconds  
and 12x20 expression bound labels will be more efficient than anything else I could do.

I am not certain.
