# Subtract two fields in a Timelion Query

**URL:** https://discuss.elastic.co/t/subtract-two-fields-in-a-timelion-query/92704
**Category:** Kibana
**Created:** [July 11, 2017, 6:31pm UTC](https://discuss.elastic.co/t/subtract-two-fields-in-a-timelion-query/92704 "2017-07-11T18:31:38Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Vinuja1](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@Vinuja1](https://discuss.elastic.co/u/Vinuja1)
#### Post date: [July 11, 2017, 6:31pm UTC](https://discuss.elastic.co/t/subtract-two-fields-in-a-timelion-query/92704/1 "2017-07-11T18:31:38Z")

</div>

Hi,

I would like to represent in Kibana the ratio Number of purchases/ Number of customers but only for the purchases with a marge superior at 10.

In other words we need to do :

es(index=log,timefield='@timstamp',q='PurchaseDone:1 AND SellPrice-BuyingPrice :\>100',metric='cardinality:ID).divide(.es(index=log,,timefield='@timestamp',metric='sum:Id'))

but it s not working.  
Do you have any ideas?

Thanks

---

<div class="post-metadata">

### Author: ![Brandon\_Kobel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_kobel/32/14829_2.png) [@Brandon\_Kobel](https://discuss.elastic.co/u/Brandon_Kobel)
#### Post date: [July 11, 2017, 7:59pm UTC](https://discuss.elastic.co/t/subtract-two-fields-in-a-timelion-query/92704/2 "2017-07-11T19:59:21Z")

</div>

@Vinuja1 what are you seeing when you try to execute that query? There are a number of syntax errors, including misspelled things like `@timstamp` and extra commas in the following fragment: `index=log,,timefield`

---

<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: [August 8, 2017, 7:59pm UTC](https://discuss.elastic.co/t/subtract-two-fields-in-a-timelion-query/92704/3 "2017-08-08T19:59:32Z")

</div>

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