# Painless script for inventory of previous week

**URL:** <https://discuss.elastic.co/t/painless-script-for-inventory-of-previous-week/308209>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [June 27, 2022, 5:26am UTC](https://discuss.elastic.co/t/painless-script-for-inventory-of-previous-week/308209 "2022-06-27T05:26:40Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![behappy\_alwayz0401](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/behappy_alwayz0401/32/105988_2.png) [@behappy\_alwayz0401](https://discuss.elastic.co/u/behappy_alwayz0401)\
**Post date:** [June 27, 2022, 5:26am UTC](https://discuss.elastic.co/t/painless-script-for-inventory-of-previous-week/308209/1 "2022-06-27T05:26:40Z")

</div>

Hi,  
I want to fetch the inventory value of the previous week. Is there a way to write a painless script for this? thanks..

---

<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:** [June 27, 2022, 6:58am UTC](https://discuss.elastic.co/t/painless-script-for-inventory-of-previous-week/308209/2 "2022-06-27T06:58:13Z")

</div>

Please provide more information, as it's not clear what you are after here.

How are you storing this inventory? What is the mapping? What are some sample events

---

<div class="post-metadata">

**Author:** ![behappy\_alwayz0401](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/behappy_alwayz0401/32/105988_2.png) [@behappy\_alwayz0401](https://discuss.elastic.co/u/behappy_alwayz0401)\
**Post date:** [June 27, 2022, 7:13am UTC](https://discuss.elastic.co/t/painless-script-for-inventory-of-previous-week/308209/3 "2022-06-27T07:13:18Z")

</div>

Let's say we are tracking week on week inventory of a retailer, every Friday.  
The Retailer ended with 200 units of Product-1 in week-1 on 17-Jun. He ended with 300 units of Product-1 in week-2 on 24-Jun. On 24-Jun, I want to run a calculation:

(Week1 ending inventory) - sales = (Week2 ending inventory)  
to perform this calculation, i need to fetch prior week (Week1) ending inventory. How can this be achieved? thanks..

---

<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:** [June 27, 2022, 7:16am UTC](https://discuss.elastic.co/t/painless-script-for-inventory-of-previous-week/308209/4 "2022-06-27T07:16:57Z")

</div>

I think you'd need to share a document example please.

---

<div class="post-metadata">

**Author:** ![behappy\_alwayz0401](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/behappy_alwayz0401/32/105988_2.png) [@behappy\_alwayz0401](https://discuss.elastic.co/u/behappy_alwayz0401)\
**Post date:** [June 27, 2022, 7:23am UTC](https://discuss.elastic.co/t/painless-script-for-inventory-of-previous-week/308209/5 "2022-06-27T07:23:32Z")

</div>

![image](https://us1.discourse-cdn.com/elastic/original/3X/1/2/122513bff1a08c3f598ba8ef080f6d47760c4d66.png)

Hope this helps...

---

<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:** [June 27, 2022, 7:37am UTC](https://discuss.elastic.co/t/painless-script-for-inventory-of-previous-week/308209/6 "2022-06-27T07:37:23Z")

</div>

Ok, but that's not in Elasticsearch, so I am not sure how we can work with that sorry.

---

<div class="post-metadata">

**Author:** ![behappy\_alwayz0401](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/behappy_alwayz0401/32/105988_2.png) [@behappy\_alwayz0401](https://discuss.elastic.co/u/behappy_alwayz0401)\
**Post date:** [June 27, 2022, 7:38am UTC](https://discuss.elastic.co/t/painless-script-for-inventory-of-previous-week/308209/7 "2022-06-27T07:38:50Z")

</div>

so are you saying there is no way to script to get previous week inventory value on a current date....?

---

<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:** [June 28, 2022, 12:27am UTC](https://discuss.elastic.co/t/painless-script-for-inventory-of-previous-week/308209/8 "2022-06-28T00:27:09Z")

</div>

Not when it's in a spreadsheet like that.

---

<div class="post-metadata">

**Author:** ![behappy\_alwayz0401](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/behappy_alwayz0401/32/105988_2.png) [@behappy\_alwayz0401](https://discuss.elastic.co/u/behappy_alwayz0401)\
**Post date:** [June 28, 2022, 7:03am UTC](https://discuss.elastic.co/t/painless-script-for-inventory-of-previous-week/308209/9 "2022-06-28T07:03:47Z")

</div>

sorry.. the spreadsheet was only for your reference to show the calculation..  
let's say a simpler example would be,  
I have a file I will upload into Kibana which has only 2 fields, Date and Sales. And all i want to do in Kibana is calculate the difference between sales on 26-Jun and sales on 27-Jun with a runtime field. Is this possible pls?

![image](https://us1.discourse-cdn.com/elastic/original/3X/7/5/75842f60157e097c628ac15024ca2a6f9de08d4d.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:** [June 28, 2022, 8:01am UTC](https://discuss.elastic.co/t/painless-script-for-inventory-of-previous-week/308209/10 "2022-06-28T08:01:05Z")

</div>

It'd be great if you could please not create multiple topics on the same question. It looks like you have a solution here, so let's close this one - [Difference between today's sales and yesterday's sales](https://discuss.elastic.co/t/difference-between-todays-sales-and-yesterdays-sales/308223)

---

<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:** [June 28, 2022, 8:01am UTC](https://discuss.elastic.co/t/painless-script-for-inventory-of-previous-week/308209/11 "2022-06-28T08:01:07Z")

</div>


