# Ignition Dataset using "view" expression from simulation tools

**URL:** <https://forum.inductiveautomation.com/t/ignition-dataset-using-view-expression-from-simulation-tools/73474>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [May 9, 2023, 1:48pm UTC](https://forum.inductiveautomation.com/t/ignition-dataset-using-view-expression-from-simulation-tools/73474 "2023-05-09T13:48:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kurt\_Lemman](https://avatars.discourse-cdn.com/v4/letter/k/7ab992/32.png) [@Kurt\_Lemman](https://forum.inductiveautomation.com/u/Kurt_Lemman)\
**Post date:** [May 9, 2023, 1:48pm UTC](https://forum.inductiveautomation.com/t/ignition-dataset-using-view-expression-from-simulation-tools/73474/1 "2023-05-09T13:48:53Z")

</div>

Disclaimer--Newbie to ignition and scripting:  
I am attempting to use the View Expression from simulation tools module to query a historical tag that is stored as a discrete value, in this case, a batch number. I want to retrieve the timestamp that indicates the start of the batch and the end of the batch and use them in a powerchart as the start and end date to allow for charting any number of stored historical attributes that might be associated with that batch.

```auto
The historical data looks like this:
Time Batch
4/25/2023 22:18 1145655
4/25/2023 23:58 1145655
4/26/2023 1:39 1145655
5/4/2023 1:10 1146131
5/4/2023 2:51 1146131
5/4/2023 4:32 1146131

```

I am attempting to use the following binding transform against a dataset retrieved from a historical binding indicated as {value} below:

view("Select min(t\_stamp) As Start, max(t\_stamp) As End, batch as Batch Group By batch",{value})

```auto
Start End Batch   
4/25/2023 22:18 4/24/2023 2:37 1145655
5/4/2023 1:10 5/4/2023 4:32 1146131

```

I want to include a “Where batch = specific batch from a drop down property  
Example: {.../Header/Details/Batch/BatchNum.props.text}” but not sure how to use the ARG’s option?

```auto
**--Desired Final Result--**
Start End Batch   
5/4/2023 1:10 5/4/2023 4:32 1146131

```

```auto
Current Results So Far:
Start End Batch
1683186524207 1683186524207 [u'1146131']

```

Any help is 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:** [May 9, 2023, 1:59pm UTC](https://forum.inductiveautomation.com/t/ignition-dataset-using-view-expression-from-simulation-tools/73474/2 "2023-05-09T13:59:11Z")

</div>

It would look something like this:

```auto
view("Select min(t_stamp) As Start, max(t_stamp) As End Where batch==args[0]",
  {value}, {path.to.batch.dropdown.prop})

```

The `args` variable is assigned a jython tuple of all of the function arguments **after** the implicit FROM dataset.

{ When posting code or logs or other text info into a topic, highlight it after pasting, and click the "PreFormatted Text" button in the comment editor toolbar. You can click the pencil icon to go back and fix things you've already posted. }

---

<div class="post-metadata">

**Author:** ![Kurt\_Lemman](https://avatars.discourse-cdn.com/v4/letter/k/7ab992/32.png) [@Kurt\_Lemman](https://forum.inductiveautomation.com/u/Kurt_Lemman)\
**Post date:** [May 9, 2023, 2:15pm UTC](https://forum.inductiveautomation.com/t/ignition-dataset-using-view-expression-from-simulation-tools/73474/3 "2023-05-09T14:15:50Z")

</div>

Thank you for the guidance!  
One last question is the formatting of the batch number comes back with the following: [u'1146131'] how can this be kept or formatted in original format as a string without brackets, u, or ' ? The original tag value that is stored in the historian is a string. I can use script to strip out the value if that is the only choice but just trying to better understand what I am seeing.

Thanks again.

---

<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:** [May 9, 2023, 2:42pm UTC](https://forum.inductiveautomation.com/t/ignition-dataset-using-view-expression-from-simulation-tools/73474/4 "2023-05-09T14:42:22Z")

</div>

> [@Kurt\_Lemman](#):
>
> without brackets, u, or '

Two things are happening here:

- When you use grouping in `view()` output columns are lists, not singletons. If you hadn't included the `AS` clause for `batch`, `view()` would have substituted `batch[0]` for you to get the singleton. When you use `AS`, you have to be explicit. Take a closer look at the grouping section of the docs.

- The `u'...'` is an artifact of converting a unicode string for display with repr(), which is invoked for list elements when converting a list to a string. Those delimiters aren't really present.

{Notice that my suggestion dropped `batch` as an output column because filtering by the same value as grouping yields just the one output row with that value.}

---

<div class="post-metadata">

**Author:** ![Kurt\_Lemman](https://avatars.discourse-cdn.com/v4/letter/k/7ab992/32.png) [@Kurt\_Lemman](https://forum.inductiveautomation.com/u/Kurt_Lemman)\
**Post date:** [May 9, 2023, 4:38pm UTC](https://forum.inductiveautomation.com/t/ignition-dataset-using-view-expression-from-simulation-tools/73474/5 "2023-05-09T16:38:04Z")

</div>

Thank you that clears things up. However, the Min(t\_stamp) and Max(t\_stamp) columns bring back the same timestamp value?

```auto
Start End
`1683186524207 1683186524207 `

```

.

---

<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:** [May 9, 2023, 4:59pm UTC](https://forum.inductiveautomation.com/t/ignition-dataset-using-view-expression-from-simulation-tools/73474/6 "2023-05-09T16:59:59Z")

</div>

Hmm. I omitted the `Group By batch` from my example. Did you put that back in?

---

<div class="post-metadata">

**Author:** ![Kurt\_Lemman](https://avatars.discourse-cdn.com/v4/letter/k/7ab992/32.png) [@Kurt\_Lemman](https://forum.inductiveautomation.com/u/Kurt_Lemman)\
**Post date:** [May 9, 2023, 5:07pm UTC](https://forum.inductiveautomation.com/t/ignition-dataset-using-view-expression-from-simulation-tools/73474/7 "2023-05-09T17:07:12Z")

</div>

No below is what I have:

`view("Select min(t_stamp) As Start,max(t_stamp) As End Where batch==args[0] Group By batch",{value}, {.../Header/Details/Batch/BatchNum.props.text})`

---

<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:** [May 9, 2023, 5:45pm UTC](https://forum.inductiveautomation.com/t/ignition-dataset-using-view-expression-from-simulation-tools/73474/8 "2023-05-09T17:45:02Z")

</div>

Please use the "Preformatted Text" button, not the quotation button, when pasting code.

---

<div class="post-metadata">

**Author:** ![Kurt\_Lemman](https://avatars.discourse-cdn.com/v4/letter/k/7ab992/32.png) [@Kurt\_Lemman](https://forum.inductiveautomation.com/u/Kurt_Lemman)\
**Post date:** [May 9, 2023, 6:03pm UTC](https://forum.inductiveautomation.com/t/ignition-dataset-using-view-expression-from-simulation-tools/73474/9 "2023-05-09T18:03:34Z")

</div>

I believe I tracked it down to the primary dataset Historical Query

Thanks for your help
