# Elasticsearch query to calculate yearly percentage growth

**URL:** <https://discuss.elastic.co/t/elasticsearch-query-to-calculate-yearly-percentage-growth/178574>\
**Category:** Elasticsearch\
**Created:** [April 26, 2019, 7:29am UTC](https://discuss.elastic.co/t/elasticsearch-query-to-calculate-yearly-percentage-growth/178574 "2019-04-26T07:29:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![prasad.ram1431](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@prasad.ram1431](https://discuss.elastic.co/u/prasad.ram1431)\
**Post date:** [April 26, 2019, 7:29am UTC](https://discuss.elastic.co/t/elasticsearch-query-to-calculate-yearly-percentage-growth/178574/1 "2019-04-26T07:29:38Z")

</div>

Hi All,

I would like to calculate yearly percentage growth of a particular field.  
Below is my sample doc for your reference.

```
{
	"stdFin": {
		"fin": {
			"numberOfStatements": 5,
			"statements": [{
					"stdViewRef": [{
						"bal": {
							"sales": 38600
						}
					}],
					"statementToDate": "2016-12-31",
					"isLatest": true
				},
				{
					"stdViewRef": [{
						"bal": {
							"sales": 3800
						}
					}],
					"statementToDate": "2015-11-11"
				},
				{
					"stdViewRef": [{
						"bal": {
							"sales": 3600
						}
					}],
					"statementToDate": "2014-01-10"
				},
			    {
					"stdViewRef": [{
						"bal": {
							"sales": 8600
						}
					}],
					"statementToDate": "2013-02-13"
				}
			]
		}
	}
}

```

In the above sample elasticsearch doc, "statementToDate" which is date field belongs to "statements" nested object, and "sales" field belongs to "stdViewRef" nested object.  
I have to calculate yearly growth of sales like, (sales\_2016 - sales\_2015)/sales\_2015 \* 100.

Could someone please help me on writing elasticsearch query.

Thanks,  
Ram

---

<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 24, 2019, 7:32am UTC](https://discuss.elastic.co/t/elasticsearch-query-to-calculate-yearly-percentage-growth/178574/2 "2019-05-24T07:32:18Z")

</div>

Closed on May 24, 2019, 7:32am UTC

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