# Difference between today's sales and yesterday's sales

**URL:** <https://discuss.elastic.co/t/difference-between-todays-sales-and-yesterdays-sales/308223>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [June 27, 2022, 9:18am UTC](https://discuss.elastic.co/t/difference-between-todays-sales-and-yesterdays-sales/308223 "2022-06-27T09:18: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, 9:18am UTC](https://discuss.elastic.co/t/difference-between-todays-sales-and-yesterdays-sales/308223/1 "2022-06-27T09:18:40Z")

</div>

We want to calculate the difference between today's sales and yesterday's sales. How can this be done with a Kibana Painless script within the Kibana user interface?  
Thanks..

---

<div class="post-metadata">

**Author:** ![ghudgins](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ghudgins/32/138532_2.png) [@ghudgins](https://discuss.elastic.co/u/ghudgins)\
**Post date:** [June 27, 2022, 12:27pm UTC](https://discuss.elastic.co/t/difference-between-todays-sales-and-yesterdays-sales/308223/2 "2022-06-27T12:27:07Z")

</div>

I think a Lens custom formula combined with a time shift is best--something like `sum(field) - sum(field, shift='1d')`

Read more about formulas in this blog [10 common Kibana visualization questions answered with formulas and time travel | Elastic Blog](https://www.elastic.co/blog/kibana-10-common-questions-formulas-time-series-maps) and in our documentation: [Create visualizations with Lens | Kibana Guide [8.2] | Elastic](https://www.elastic.co/guide/en/kibana/current/lens.html#lens-formulas)

---

<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, 3:30pm UTC](https://discuss.elastic.co/t/difference-between-todays-sales-and-yesterdays-sales/308223/3 "2022-06-27T15:30:07Z")

</div>

Thank you.. this seems to be a good solution. Will try it out and get back

---

<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:23am UTC](https://discuss.elastic.co/t/difference-between-todays-sales-and-yesterdays-sales/308223/4 "2022-06-28T07:23:03Z")

</div>

In lens, I performed the following:  
**Step1:**  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/5/7533414470d3f156ca87c0cb1dc0a0b8125298b1.png)

**Step2:**  
Then under metrics, in the right hand side, I added one more reported Inv with time shift of 1 week as shown here:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/b/7be1dfc9a8bb69cf2c63e22e7c064b0d8cbb6e61.png)

**Step3:**  
After adding the time shift field, i get the error on the left that you see in the pic above..

**Step4:**  
If i were to remove the "top values of SKU" field from the lens, then I get this error:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/6/a602ca995f3f90165643f939ead711dcb2e87353.png)

I need to have both the SKU and the weekend date showing in the report.

**Additionally:**  
the date format has been set in the index as a date with format "Jan 1, 2022 @ 00:00:00.000"  
and the SKU is a keyword.

---

<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 29, 2022, 1:48am UTC](https://discuss.elastic.co/t/difference-between-todays-sales-and-yesterdays-sales/308223/5 "2022-06-29T01:48:02Z")

</div>

Hello any help with this please

---

<div class="post-metadata">

**Author:** ![ghudgins](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ghudgins/32/138532_2.png) [@ghudgins](https://discuss.elastic.co/u/ghudgins)\
**Post date:** [July 5, 2022, 9:10pm UTC](https://discuss.elastic.co/t/difference-between-todays-sales-and-yesterdays-sales/308223/6 "2022-07-05T21:10:03Z")

</div>

the first error looks like it's not happy with using top values & time shifts. this is because the system isn't sure how to return top values in these cases. you could try to include the SKUs you want as rows manually by using the Filters aggregation as the error suggests (instead of dynamic top values).

the second error looks like a data problem...something with that runtime field you're using for "Weekend Date". it's odd because that date doesn't look wrong. i'm not sure the best way to resolve that

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [July 5, 2022, 9:24pm UTC](https://discuss.elastic.co/t/difference-between-todays-sales-and-yesterdays-sales/308223/7 "2022-07-05T21:24:10Z")

</div>

Not to inject out of place ... but the `date` and the expected format do not match that is why there is a parse error, somewhere you need to put in the correct format

 ![Screen Shot 2022-07-05 at 2.20.06 PM](https://us1.discourse-cdn.com/elastic/original/3X/5/7/576995c7dab72b6f91c5cf243ad4ee6d6fee7fa9.png)

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [July 6, 2022, 2:55am UTC](https://discuss.elastic.co/t/difference-between-todays-sales-and-yesterdays-sales/308223/8 "2022-07-06T02:55:19Z")

</div>

@ghudgins I think there may be a challenge when using a non-normal @timestamp for a time shift... strangely today I just ran into the same issue when I tried to shift with a month..

---

<div class="post-metadata">

**Author:** ![ghudgins](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ghudgins/32/138532_2.png) [@ghudgins](https://discuss.elastic.co/u/ghudgins)\
**Post date:** [July 6, 2022, 3:32pm UTC](https://discuss.elastic.co/t/difference-between-todays-sales-and-yesterdays-sales/308223/9 "2022-07-06T15:32:32Z")

</div>

_facepalm_ it's exactly that. nice catch!

---

<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:** [July 6, 2022, 4:54pm UTC](https://discuss.elastic.co/t/difference-between-todays-sales-and-yesterdays-sales/308223/10 "2022-07-06T16:54:41Z")

</div>

Thank you! These insights are very helpful…

---

<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:** [August 3, 2022, 4:55pm UTC](https://discuss.elastic.co/t/difference-between-todays-sales-and-yesterdays-sales/308223/11 "2022-08-03T16:55:20Z")

</div>

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