# Calculating percentage growth on Nested Fields

**URL:** <https://discuss.elastic.co/t/calculating-percentage-growth-on-nested-fields/165710>\
**Category:** Elasticsearch\
**Created:** [January 25, 2019, 7:25am UTC](https://discuss.elastic.co/t/calculating-percentage-growth-on-nested-fields/165710 "2019-01-25T07:25:41Z")\
**Posts on this page:** 3\
**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:** [January 25, 2019, 7:25am UTC](https://discuss.elastic.co/t/calculating-percentage-growth-on-nested-fields/165710/1 "2019-01-25T07:25:41Z")

</div>

Hi All,

I would like to calculate, fastest growing company(each document is a company) in Germany for the year 2016 with the below formula,  
(New value - original value)\*100/original value  
I have below structure in my ES index,

> ```
> {
> "allData": [{
> "currency": [{
> "pAndL": {
> "netSales": 59955
> }
> }],
> "stmtDate": "2015-03-31",
> "isLatest": true
> },
> {
> "currency": [{
> "pAndL": {
> "netSales": 63134
> }
> }],
> "stmtDate": "2014-03-31"
> }
> ]
> }
> 
> ```

From the above structure New value will be netSales where isLatest is true and original value will be netSales from other object.  
Along with the above two object sometimes I may contain more than two objects.  
Could someone please help me on writing Elasticsearch query for fulfilling this requirement.

Thanks,  
Ram

---

<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:** [January 31, 2019, 7:27am UTC](https://discuss.elastic.co/t/calculating-percentage-growth-on-nested-fields/165710/2 "2019-01-31T07:27:34Z")

</div>

Hello,

Any inputs please.

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:** [February 28, 2019, 7:27am UTC](https://discuss.elastic.co/t/calculating-percentage-growth-on-nested-fields/165710/3 "2019-02-28T07:27:36Z")

</div>

Closed on February 28, 2019, 7:27am UTC

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