# Conditional math expression in TSVB

**URL:** <https://discuss.elastic.co/t/conditional-math-expression-in-tsvb/220703>\
**Category:** Kibana\
**Created:** [February 24, 2020, 5:26pm UTC](https://discuss.elastic.co/t/conditional-math-expression-in-tsvb/220703 "2020-02-24T17:26:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tshayan](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@tshayan](https://discuss.elastic.co/u/tshayan)\
**Post date:** [February 24, 2020, 5:26pm UTC](https://discuss.elastic.co/t/conditional-math-expression-in-tsvb/220703/1 "2020-02-24T17:26:37Z")

</div>

Hello,

I am just curious if it would be possible to write a conditional statement inside the expression editor of the TSVB Math aggregation. For instance, consider I have an aggregation in TSVB metric which calculates an average of numbers. Then I create a new math aggregation, set the average equal to the "test" variable, and inside the Math expression editor I want to write something like:

```
if(params.test > 500){
   return add(300,params.test)
} else {
   return subtract(300,params.test)
}

```

Thanks.

---

<div class="post-metadata">

**Author:** ![tshayan](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@tshayan](https://discuss.elastic.co/u/tshayan)\
**Post date:** [February 24, 2020, 5:55pm UTC](https://discuss.elastic.co/t/conditional-math-expression-in-tsvb/220703/2 "2020-02-24T17:55:54Z")

</div>

Correct me if I'm wrong but looks like this would be possible using the "Bucket Script" aggregation in TSVB rather that the Math aggregation.

Still curious to know if the Math aggregation would support something like this.

---

<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:** [March 23, 2020, 5:56pm UTC](https://discuss.elastic.co/t/conditional-math-expression-in-tsvb/220703/3 "2020-03-23T17:56:00Z")

</div>

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