# How to subtract between two fields?

**URL:** https://discuss.elastic.co/t/how-to-subtract-between-two-fields/101250
**Category:** Kibana
**Created:** [September 21, 2017, 12:09am UTC](https://discuss.elastic.co/t/how-to-subtract-between-two-fields/101250 "2017-09-21T00:09:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![adnil](https://avatars.discourse-cdn.com/v4/letter/a/dc4da7/32.png) [@adnil](https://discuss.elastic.co/u/adnil)
#### Post date: [September 21, 2017, 12:09am UTC](https://discuss.elastic.co/t/how-to-subtract-between-two-fields/101250/1 "2017-09-21T00:09:24Z")

</div>

New to this but tried to follow the Elastic docs and it didn't work for me. Trying to create a Visualizer where I want to subtract field1 from field2 using the Advanced JSON scripting. Keeps saying I have an error but not sure what the error is. Tried also with 'Filters' aggregation and got same result. I must be missing something very simple so please guide me; please see attached screenshots. Thanks.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/5/a56749f062c94ef877cd7e507a4e27ef4a388b32.png)

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

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [September 21, 2017, 4:02am UTC](https://discuss.elastic.co/t/how-to-subtract-between-two-fields/101250/2 "2017-09-21T04:02:25Z")

</div>

You will probably want to create a scripted field instead [https://www.elastic.co/guide/en/kibana/5.6/scripted-fields.html](https://www.elastic.co/guide/en/kibana/5.6/scripted-fields.html)

---

<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: [October 19, 2017, 4:03am UTC](https://discuss.elastic.co/t/how-to-subtract-between-two-fields/101250/3 "2017-10-19T04:03:17Z")

</div>

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