# TSVB - Creating variables for Math

**URL:** <https://discuss.elastic.co/t/tsvb-creating-variables-for-math/228385>\
**Category:** Kibana\
**Created:** [April 16, 2020, 5:35pm UTC](https://discuss.elastic.co/t/tsvb-creating-variables-for-math/228385 "2020-04-16T17:35:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![adahn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adahn/32/45475_2.png) [@adahn](https://discuss.elastic.co/u/adahn)\
**Post date:** [April 16, 2020, 5:35pm UTC](https://discuss.elastic.co/t/tsvb-creating-variables-for-math/228385/1 "2020-04-16T17:35:30Z")

</div>

I'd like to create a TSVB Metric using the Math aggregation. I would like to create two variables using filters, so I know I need to set up those aggregations before the Math module, but I'm having trouble figuring out how.

Basically I want to create:  
Variable A - Count of documents matching one query  
Variable B - Count of documents matching a different query  
Use Math aggregation to work on those variables and output a single number displayed as Metric

---

<div class="post-metadata">

**Author:** ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)\
**Post date:** [April 16, 2020, 7:24pm UTC](https://discuss.elastic.co/t/tsvb-creating-variables-for-math/228385/2 "2020-04-16T19:24:42Z")

</div>

Doing math on two different sets of documents is not supported in TSVB, with one exception: if you want to divide, then there is the metric called "Filter Ratio" which accepts two filters. If you just want to display the count of two different sets of documents, you can split by the Filters aggregation.

The most flexible query-building tool we have is Vega, but it's much harder to use than TSVB. You may want to look into it.

---

<div class="post-metadata">

**Author:** ![adahn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adahn/32/45475_2.png) [@adahn](https://discuss.elastic.co/u/adahn)\
**Post date:** [April 16, 2020, 7:41pm UTC](https://discuss.elastic.co/t/tsvb-creating-variables-for-math/228385/3 "2020-04-16T19:41:26Z")

</div>

Thanks, wylie. I've made some progress using Filter Ratio to compare the sets of documents, and then taking the output of that as a variable in Math, which has definitely gotten me closer to the measurement I had in mind.

---

<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:** [May 14, 2020, 7:46pm UTC](https://discuss.elastic.co/t/tsvb-creating-variables-for-math/228385/4 "2020-05-14T19:46:27Z")

</div>

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