# Calculus between two fields

**URL:** <https://discuss.elastic.co/t/calculus-between-two-fields/210170>\
**Category:** Kibana\
**Created:** [December 2, 2019, 11:22am UTC](https://discuss.elastic.co/t/calculus-between-two-fields/210170 "2019-12-02T11:22:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![florent1](https://avatars.discourse-cdn.com/v4/letter/f/87869e/32.png) [@florent1](https://discuss.elastic.co/u/florent1)\
**Post date:** [December 2, 2019, 11:22am UTC](https://discuss.elastic.co/t/calculus-between-two-fields/210170/1 "2019-12-02T11:22:00Z")

</div>

Hello,

I'm new to ES and Kibana and I think these are amazing tools ! However, I'm having a hard time making calculus on several values. Here is my problem : I'm making a website for a brand that has several shops, and I need to make a dashboard for them where they can see a percentage of difference in sales values between one specific shop compare to all the other shops. So I really need to make a calculus like : (global sales values – shop sales values) / sales values \* 100.

Anyway I've searched a lot but I cannot really find the best way to do it. I'd love to use Timelion but in the end I only need a number displayed, not a whole chart. Should I use a script ?

Thanks a lot in advance if you take the time to help me, and please excuse my poor english skills.

---

<div class="post-metadata">

**Author:** ![Liza\_Katz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/liza_katz/32/52358_2.png) [@Liza\_Katz](https://discuss.elastic.co/u/Liza_Katz)\
**Post date:** [December 2, 2019, 4:23pm UTC](https://discuss.elastic.co/t/calculus-between-two-fields/210170/2 "2019-12-02T16:23:07Z")

</div>

You can achieve this by using TSVB (Time Series Visual Builder).

1. Go to TSVB \> Metric.
2. Add the following type of aggregation to calculate the ratio between store sales and global sales (I used data from the eCommerce sample data set)

 ![Selection_160](https://us1.discourse-cdn.com/elastic/original/3X/4/5/45a603ea6866da0a773b9587ac7864bf3d24920a.png)

1. Perform the remaining part of the calculation by adding am additional sub aggregation (by clicking on the small + icon in the right corner)

 ![Selection_161](https://us1.discourse-cdn.com/elastic/original/3X/2/0/20f672e051d7b7d7f6872d44f179d3a49f2c5c97.png)

1. Use the Options panel to adjust formatting, add a meaningful label.

![Selection_162](https://us1.discourse-cdn.com/elastic/original/3X/b/3/b385abeb377840668d8c58d3cf8da6b39f1d9ce0.png)

1. Voila!

![Selection_163](https://us1.discourse-cdn.com/elastic/original/3X/6/f/6fdfe33e072c522d72bdcdec76f072e7040f3df4.png)

---

<div class="post-metadata">

**Author:** ![florent1](https://avatars.discourse-cdn.com/v4/letter/f/87869e/32.png) [@florent1](https://discuss.elastic.co/u/florent1)\
**Post date:** [December 3, 2019, 8:55am UTC](https://discuss.elastic.co/t/calculus-between-two-fields/210170/3 "2019-12-03T08:55:59Z")

</div>

Thanks a lot for your reply, this is exactly what I'm looking for.  
I'm sorry but I'm not sure how to reach the type I'm looking for through the Numerator and Denominator fields. This is weird, because I have no problem with this in other Kibana visualizations. i.e, I would like to reach the "total" type in this document :

```
{
    "id": 52,
    "checkoutCompletedAt": "2018-11-29T16:15:25+01:00",
    "number": "000000031",
    "items": [
        {
            "id": 45,
            "quantity": 1,
            "unitPrice": 1713,
            "total": 1713

```

Sorry if it seems obvious, I'm having troubles using TSVB for now.

---

<div class="post-metadata">

**Author:** ![Liza\_Katz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/liza_katz/32/52358_2.png) [@Liza\_Katz](https://discuss.elastic.co/u/Liza_Katz)\
**Post date:** [December 9, 2019, 4:57pm UTC](https://discuss.elastic.co/t/calculus-between-two-fields/210170/4 "2019-12-09T16:57:54Z")

</div>

Hey florent,  
Can you elaborate a little more on what exactly is not working for you, so I can test this?

---

<div class="post-metadata">

**Author:** ![florent1](https://avatars.discourse-cdn.com/v4/letter/f/87869e/32.png) [@florent1](https://discuss.elastic.co/u/florent1)\
**Post date:** [December 10, 2019, 1:15pm UTC](https://discuss.elastic.co/t/calculus-between-two-fields/210170/5 "2019-12-10T13:15:24Z")

</div>

Thanks a lot for answering. me I could finally find my issue with TSVB : the timerange I chose was not correct.  
Now I'm trying to calculate a ratio in the same way with a boolean but I cannot make it work using "nameOfMyBoolean": true as a numerator and "nameOfMyBoolean": false. Is it possible to use booleans with TSVB ?

---

<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:** [January 7, 2020, 1:15pm UTC](https://discuss.elastic.co/t/calculus-between-two-fields/210170/6 "2020-01-07T13:15:43Z")

</div>

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