# Expression to get value from dataset

**URL:** <https://forum.inductiveautomation.com/t/expression-to-get-value-from-dataset/37856>\
**Category:** Ignition\
**Created:** [August 18, 2020, 2:03pm UTC](https://forum.inductiveautomation.com/t/expression-to-get-value-from-dataset/37856 "2020-08-18T14:03:46Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![vrautomation](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/vrautomation/32/11155_2.png) [@vrautomation](https://forum.inductiveautomation.com/u/vrautomation)\
**Post date:** [August 18, 2020, 2:03pm UTC](https://forum.inductiveautomation.com/t/expression-to-get-value-from-dataset/37856/1 "2020-08-18T14:03:46Z")

</div>

Very simple question. I’m sure the answer is simple too.

Is there an expression function to read a value from a dataset? Something like getValueAt in Python.

Thanks.

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [August 18, 2020, 2:12pm UTC](https://forum.inductiveautomation.com/t/expression-to-get-value-from-dataset/37856/2 "2020-08-18T14:12:32Z")

</div>

You can use square brackets to read values from a dataset in expressions. The following will read the “Id” column of row 0.

```auto
{Root Container.myTable.data}[0, "Id"]

```

And yes, it also baffles me why this is possible in expressions but not in python…

Extra hint: to read the selected row, it’s best to wrap it in a try clause and give a default return value. That way, you don’t get errors when no row is selected. The following expression will give `-1` when no row is selected.

```auto
try({Root Container.myTable.data}[{Root Container.myTable.selectedRow}, "Id"], -1)

```

---

<div class="post-metadata">

**Author:** ![vrautomation](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/vrautomation/32/11155_2.png) [@vrautomation](https://forum.inductiveautomation.com/u/vrautomation)\
**Post date:** [August 18, 2020, 4:13pm UTC](https://forum.inductiveautomation.com/t/expression-to-get-value-from-dataset/37856/3 "2020-08-18T16:13:11Z")

</div>

Very good. Thank you!

---

<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:** [August 18, 2020, 4:29pm UTC](https://forum.inductiveautomation.com/t/expression-to-get-value-from-dataset/37856/4 "2020-08-18T16:29:42Z")

</div>

> [@Sanderd17](#):
>
> And yes, it also baffles me why this is possible in expressions but not in python…

I mean, it wouldn't be valid syntax in Python? Subscript keys can only be a single object. `dataset[(0, "Id")]` seems pretty silly to me. If you want more Pythonic access, use a pydataset - `dataset[0]["id"]`?

---

<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:** [August 18, 2020, 4:47pm UTC](https://forum.inductiveautomation.com/t/expression-to-get-value-from-dataset/37856/5 "2020-08-18T16:47:33Z")

</div>

It is possible, but not default, for a python object’s ` __getitem__ ` and ` __setitem__ ` to handle a tuple. So a custom jython wrapper for `Dataset` could be registered to support such syntax. If such a wrapper implemented the complete `sequence` interface, the PyDataset type would no longer be necessary.

---

<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:** [August 18, 2020, 4:55pm UTC](https://forum.inductiveautomation.com/t/expression-to-get-value-from-dataset/37856/6 "2020-08-18T16:55:10Z")

</div>

> [@pturmel](#):
>
> If such a wrapper implemented the complete `sequence` interface, the PyDataset type would no longer be necessary.

Yeah, but registering a wrapper for Dataset could instantly break basically every script anyone's ever written...high regression risk for relatively minor syntax gain (IMO).

---

<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:** [August 18, 2020, 4:55pm UTC](https://forum.inductiveautomation.com/t/expression-to-get-value-from-dataset/37856/7 "2020-08-18T16:55:45Z")

</div>

FWIW, I have considered injecting such a wrapper in my Simulation Aids module, similar to the way I made PyComponentWrapper uniform across the Swing side of the platform. If I did so, all java objects that implement the dataset interface would suddenly have pythonic semantics everywhere in the _entire_ platform.

---

<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:** [August 18, 2020, 4:59pm UTC](https://forum.inductiveautomation.com/t/expression-to-get-value-from-dataset/37856/8 "2020-08-18T16:59:41Z")

</div>

> [@paul-griffith](#):
>
> could instantly break basically every script

Only if you are already registering a custom wrapper for datasets. What I have in mind would preserve the automatic java-jython wrapper's functionality for each implementing class. The only exception would be where Dataset implementations also implemented python's sequence interface.

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [August 18, 2020, 5:34pm UTC](https://forum.inductiveautomation.com/t/expression-to-get-value-from-dataset/37856/9 "2020-08-18T17:34:34Z")

</div>

> [@paul-griffith](#):
>
> Subscript keys can only be a single object. `dataset[(0, "Id")]` seems pretty silly to me

Actually, it's the comma that makes the tuple, not the parentheses. So `dataset[0, "Id"]` is the same as `dataset[(0, "Id")]`.

But even `dataset[0]["Id"]` would look nicer to me.

---

<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:** [August 18, 2020, 5:37pm UTC](https://forum.inductiveautomation.com/t/expression-to-get-value-from-dataset/37856/10 "2020-08-18T17:37:09Z")

</div>

> [@Sanderd17](#):
>
> Actually, it’s the comma that makes the tuple, not the parentheses

TIL you can do that in subscript expressions. Neat. Something like @pturmel suggested might happen (in the future) but not anytime soon.

---

<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:** [August 18, 2020, 5:38pm UTC](https://forum.inductiveautomation.com/t/expression-to-get-value-from-dataset/37856/11 "2020-08-18T17:38:42Z")

</div>

> [@Sanderd17](#):
>
> Actually, it’s the comma that makes the tuple, not the parentheses.

Yes, that's what I meant.

> [@Sanderd17](#):
>
> But even `dataset[0]["Id"]` would look nicer to me.

Nah. But it is compatible with slice notation.

---

<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:** [July 25, 2023, 11:16am UTC](https://forum.inductiveautomation.com/t/expression-to-get-value-from-dataset/37856/13 "2023-07-25T11:16:52Z")

</div>

> [@samer\_samy](#):
>
> 'Shipped Pallets data : '+{value}+' Pallets, '+len({.../Table.props.data}["LOT"])+' LOT, '+len({.../Table.props.data}["OrderKey"])+' Order.'

Tips:  
Add a little air into your expressions to make them easier to read and format code on the forum using the \</\> button.

```auto
'Shipped Pallets data : ' 
+ {value} + ' Pallets, '
+ len({.../Table.props.data}["LOT"]) + ' LOT, '
+ len({.../Table.props.data}["OrderKey"]) + ' Order.'

```

will be much easier to read and debug and anyone maintaining the code after you will appreciate it. The expression language ignores line breaks and spaces outside of functions, etc.

---

<div class="post-metadata">

**Author:** ![aaron1](https://avatars.discourse-cdn.com/v4/letter/a/b5a626/32.png) [@aaron1](https://forum.inductiveautomation.com/u/aaron1)\
**Post date:** [January 17, 2025, 4:02am UTC](https://forum.inductiveautomation.com/t/expression-to-get-value-from-dataset/37856/14 "2025-01-17T04:02:55Z")

</div>

Is it possible to read a whole row of data? It doesn't seem to like referencing just the row index... `{Root Container.myTable.data}[0]` ❌

---

<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:** [January 17, 2025, 1:08pm UTC](https://forum.inductiveautomation.com/t/expression-to-get-value-from-dataset/37856/15 "2025-01-17T13:08:06Z")

</div>

No, the single subscript syntax for dataset access is documented to mean selecting the given **column** from row zero.
