# Storing a value before filterrows and accessing it after

**URL:** <https://discuss.elastic.co/t/storing-a-value-before-filterrows-and-accessing-it-after/333239>\
**Category:** Kibana\
**Tags:** canvas\
**Created:** [May 11, 2023, 11:23pm UTC](https://discuss.elastic.co/t/storing-a-value-before-filterrows-and-accessing-it-after/333239 "2023-05-11T23:23:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![B\_Hart](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/b_hart/32/120932_2.png) [@B\_Hart](https://discuss.elastic.co/u/B_Hart)\
**Post date:** [May 11, 2023, 11:23pm UTC](https://discuss.elastic.co/t/storing-a-value-before-filterrows-and-accessing-it-after/333239/1 "2023-05-11T23:23:20Z")

</div>

I have a situation where I want to filter rows out, but I want to save the number of pre-filtered rows into variable to use later in the variable expression editor (specifically to calculate a percentage value with the pre- and post-filtered values)

How do I accomplish this? I attemped to store the value in a variable via var\_set, but apparently var\_set doesn't do what I expected because it nullified all my table data when I tried to set it.

```auto
| esdocs index="phil.test" fields="fileInspected.filename, fileInspected.fileInfo.fileAttributes"
| var name="totalfiles"
| var_set name="totalfiles" value="size(fileInspected.filename)"
| filterrows {getCell "fileInspected.fileInfo.fileAttributes" | eq "FILE_ATTRIBUTE_ARCHIVE"}
| math "size(fileInspected.filename)/totalfiles"

```

The above doesn't work... depending on how I write this either the variable is not recognized in the math function... or my entire table is removed and replaced.

Is it possible to store a value in the expression editor?

---

<div class="post-metadata">

**Author:** ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)\
**Post date:** [May 31, 2023, 11:28pm UTC](https://discuss.elastic.co/t/storing-a-value-before-filterrows-and-accessing-it-after/333239/2 "2023-05-31T23:28:31Z")

</div>

The [`createTable`](https://www.elastic.co/guide/en/kibana/current/canvas-function-reference.html#createTable_fn) example in the Canvas function reference shows how `var_set` can be used to achieve a goal like this.

Rather than using the `esdocs` function and using `filterrows` to isolate the non-applicable data, have you thought of using `essql` to get the total number of docments, and to select the applicable documents in a query?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 28, 2023, 11:29pm UTC](https://discuss.elastic.co/t/storing-a-value-before-filterrows-and-accessing-it-after/333239/3 "2023-06-28T23:29:11Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
