# Lens Metric - subtract a value based of number of days in query

**URL:** https://discuss.elastic.co/t/lens-metric-subtract-a-value-based-of-number-of-days-in-query/301927
**Category:** Kibana
**Tags:** lens
**Created:** [April 8, 2022, 7:02am UTC](https://discuss.elastic.co/t/lens-metric-subtract-a-value-based-of-number-of-days-in-query/301927 "2022-04-08T07:02:42Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![sqbell](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@sqbell](https://discuss.elastic.co/u/sqbell)
#### Post date: [April 8, 2022, 7:02am UTC](https://discuss.elastic.co/t/lens-metric-subtract-a-value-based-of-number-of-days-in-query/301927/1 "2022-04-08T07:02:42Z")

</div>

Hi,

I'm trying to create a metric that would show our profits. I'm using Lens Metric and the calculation so far is like so:

```auto
round((round((sum(money_amount_eur_reverse, kql='type:bet_transaction OR type:settle_transaction') * 0.75), 2) - sum(money_amount_eur, kql='type:bonus_transaction AND money_amount_eur > 0')) * 0.7, 2)

```

From this number I would like to subtract a static number that we pay each day. But I would also like it be multiplied by number of days selected in the dashboard's query. So if 24 hours are selected it would subtract x and if 30 days - 30 \* x.

Is there any way to achieve this?

---

<div class="post-metadata">

### Author: ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)
#### Post date: [April 11, 2022, 7:46am UTC](https://discuss.elastic.co/t/lens-metric-subtract-a-value-based-of-number-of-days-in-query/301927/2 "2022-04-11T07:46:50Z")

</div>

It sounds what you actually want is this feature: [[Lens] Time scaling without date histogram · Issue #79656 · elastic/kibana · GitHub](https://github.com/elastic/kibana/issues/79656)

But unfortunately it's not implemented yet.

I can think of a workaround though which might work for you:

- Create a runtime field `currentDay` which outputs the current day per document (similar to [Manipulate time using Elastic runtime fields from elastic content share](https://elastic-content-share.eu/runtime-fields/manipulate-time/)) - e.g. for `2022-04-04 12:45:23` the runtime field would be a keyword `2022-04-04`.
- Then, add the following to your formula: `+ unique_count(currentDay) * x`

It will not work for partial days (e.g. on selecting half a day), but that might be just what you needx

---

<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: [May 9, 2022, 7:47am UTC](https://discuss.elastic.co/t/lens-metric-subtract-a-value-based-of-number-of-days-in-query/301927/3 "2022-05-09T07:47:27Z")

</div>

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