# How to create aging column for number of days wanted

**URL:** https://discuss.elastic.co/t/how-to-create-aging-column-for-number-of-days-wanted/254556
**Category:** Kibana
**Created:** [November 6, 2020, 4:05pm UTC](https://discuss.elastic.co/t/how-to-create-aging-column-for-number-of-days-wanted/254556 "2020-11-06T16:05:16Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![khairul\_faiz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/khairul_faiz/32/78579_2.png) [@khairul\_faiz](https://discuss.elastic.co/u/khairul_faiz)
#### Post date: [November 6, 2020, 4:05pm UTC](https://discuss.elastic.co/t/how-to-create-aging-column-for-number-of-days-wanted/254556/1 "2020-11-06T16:05:16Z")

</div>

hi can anyone share their experience in creating aging column?  
the process is i need to calculate aging of days that a payment made between number of days invoice date - invoice due date

thank you for sharing

---

<div class="post-metadata">

### Author: ![ylasri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ylasri/32/86120_2.png) [@ylasri](https://discuss.elastic.co/u/ylasri)
#### Post date: [November 6, 2020, 4:16pm UTC](https://discuss.elastic.co/t/how-to-create-aging-column-for-number-of-days-wanted/254556/2 "2020-11-06T16:16:20Z")

</div>

You can calculate the aging using Kibana scripted fields  
So Basically you can a new scripted field called "aging\_das" to your invoices index pattern then use this fiel to build a histogram based 30 days for example ...

Here is a snippet on how to add a scripted field on a DSL query, same painless code can be used in Kibana scripted field

```auto
GET invoices-payments/_search
{
  "_source": ["invoice_date", "due_date", "invoice_id"],  
  "script_fields": {
    "aging_days": {
      "script": {
        "source": "(doc['due_date'].value.toInstant().toEpochMilli() - doc['invoice_date'].value.toInstant().toEpochMilli()) / params.factor",
        "params": {
          "factor": 86400000
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![khairul\_faiz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/khairul_faiz/32/78579_2.png) [@khairul\_faiz](https://discuss.elastic.co/u/khairul_faiz)
#### Post date: [November 13, 2020, 2:19am UTC](https://discuss.elastic.co/t/how-to-create-aging-column-for-number-of-days-wanted/254556/3 "2020-11-13T02:19:11Z")

</div>

hi thanks for the shared script, but how can i add this script to the scripted field?

when i tried to add this snippet to scipted field on index patern it show errors  
sorry im new to kibnana so a lot of alien things for me

 ![Screenshot 2020-11-13 at 10.17.54 AM](https://us1.discourse-cdn.com/elastic/original/3X/4/a/4ad5b70094a35c53b1eecf00d003cd2548a8bad7.jpeg)

---

<div class="post-metadata">

### Author: ![ylasri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ylasri/32/86120_2.png) [@ylasri](https://discuss.elastic.co/u/ylasri)
#### Post date: [November 13, 2020, 8:52am UTC](https://discuss.elastic.co/t/how-to-create-aging-column-for-number-of-days-wanted/254556/4 "2020-11-13T08:52:20Z")

</div>

Use only the content of the source like this

```auto
(doc['due_date'].value.toInstant().toEpochMilli() - doc['invoice_date'].value.toInstant().toEpochMilli()) / 86400000

```

---

<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: [December 11, 2020, 8:52am UTC](https://discuss.elastic.co/t/how-to-create-aging-column-for-number-of-days-wanted/254556/5 "2020-12-11T08:52:36Z")

</div>

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