# Elasticsearch: create a new field based on the value of other fields in a time range

**URL:** <https://discuss.elastic.co/t/elasticsearch-create-a-new-field-based-on-the-value-of-other-fields-in-a-time-range/372929>\
**Category:** Elasticsearch\
**Created:** [January 8, 2025, 10:13am UTC](https://discuss.elastic.co/t/elasticsearch-create-a-new-field-based-on-the-value-of-other-fields-in-a-time-range/372929 "2025-01-08T10:13:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sahere37](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@sahere37](https://discuss.elastic.co/u/sahere37)\
**Post date:** [January 8, 2025, 10:13am UTC](https://discuss.elastic.co/t/elasticsearch-create-a-new-field-based-on-the-value-of-other-fields-in-a-time-range/372929/1 "2025-01-08T10:13:17Z")

</div>

Hi all, I have some data in different timestamps as below image, imaging that the fields are "src label", "src value" "dst label" , "dst value" and timestamp.

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

how can I define a new fields named as "In" based on the above data in a time range?  
the target "In" field for each specific label will be calculated base on the sum of "src value" and "dst value" of each document which respectively their "src label" and "dst label" is the mentioned specific value as below:

```auto
for example the "In" value for label= Inf in a time range is calculated based on the sum of "src value" for those "src label" which are equal to "Inf" and sum of "dst value" for those "dst label" which are equal to "Inf" in the requested time range:
In=12000+10+500+1900+915=15325

```

same as "In" for "Inf" label, the "In" value for "Tst" and "Pst" labels should be as below:

```auto
In (for Tst)= 450+201+540+756=1947
In (for Pst)= 104+112+814=1030

```

and finally I want to have a visualize table same as below image in the desired time range:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/8/f/8f93adff345902bd0859949b7da68f97e54f41e6.png)

any help will be so appreciated

Regards
