# Metric and multi-option controls

**URL:** https://discuss.elastic.co/t/metric-and-multi-option-controls/352807
**Category:** Kibana
**Tags:** dashboard, visualisation
**Created:** [February 8, 2024, 12:22am UTC](https://discuss.elastic.co/t/metric-and-multi-option-controls/352807 "2024-02-08T00:22:53Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![rastro](https://avatars.discourse-cdn.com/v4/letter/r/b782af/32.png) [@rastro](https://discuss.elastic.co/u/rastro)
#### Post date: [February 8, 2024, 12:22am UTC](https://discuss.elastic.co/t/metric-and-multi-option-controls/352807/1 "2024-02-08T00:22:53Z")

</div>

Here's a simplified example. I run a business with 2 locations. I have a daily document in an index that stores the number of employees in that location.

Now, I'd like to have a dashboard that shows a legacy metric for the number of employees, which would be the "Last Value". That works great, until...

I'd like to add a Control to the dashboard so I can select which location I'm viewing. If I select one location, it still works fine. However, if I select two locations (you know, to see my entire business), it still picks a single "Last Value" (i.e. whichever location was added last).

Is there a way to allow the control to properly affect the metric - to create a sum(Last Value)?

---

<div class="post-metadata">

### Author: ![jsanz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jsanz/32/53734_2.png) [@jsanz](https://discuss.elastic.co/u/jsanz)
#### Post date: [February 8, 2024, 3:04pm UTC](https://discuss.elastic.co/t/metric-and-multi-option-controls/352807/2 "2024-02-08T15:04:12Z")

</div>

I think you want to use the **Collapse** option in Lens where you define a criteria to break your metric and then put the values all together again, but for this you need to use the new metric.

Sample data for my test:

```auto
# Create the index
PUT discuss-352807
{
  "mappings": {
    "properties": {
      "timestamp": { "type": "date"},
      "location": { "type": "keyword"},
      "employees": { "type": "integer"}
    }
  }
}

# Add three days of data for two locations
POST discuss-352807/_bulk
{ "index": {}}
{"timestamp": "2024-02-05", "location": "A", "employees": 10}
{ "index": {}}
{"timestamp": "2024-02-05", "location": "B", "employees": 5}
{ "index": {}}
{"timestamp": "2024-02-06", "location": "A", "employees": 12}
{ "index": {}}
{"timestamp": "2024-02-06", "location": "B", "employees": 8}
{ "index": {}}
{"timestamp": "2024-02-08", "location": "A", "employees": 14}
{ "index": {}}
{"timestamp": "2024-02-08", "location": "B", "employees": 11}

# Create a data view
POST kbn:/api/data_views/data_view
{
  "data_view": {

  "title": "discuss-352807",
  "timeFieldName": "timestamp"
  }}

```

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/1/9/191eaa958d80bf890bcf8b1ecb49d0e5aea2eac9.png)

And this is how it looks like in a dashboard with a control for location.

![Peek 2024-02-08 16-02](https://us1.discourse-cdn.com/elastic/original/3X/4/c/4c5d4dd243d29e083c310531c0b539fd015d2529.gif)

---

<div class="post-metadata">

### Author: ![rastro](https://avatars.discourse-cdn.com/v4/letter/r/b782af/32.png) [@rastro](https://discuss.elastic.co/u/rastro)
#### Post date: [February 8, 2024, 8:48pm UTC](https://discuss.elastic.co/t/metric-and-multi-option-controls/352807/3 "2024-02-08T20:48:27Z")

</div>

That worked for the non-legacy metric. Thanks. Hopefully the users won't complain about the UI.

Now that I might be able to use the control on my dashboard, I have other visualizations that also aren't working (area stacked, for one). It seems that best practice is to open another topic?

---

<div class="post-metadata">

### Author: ![jsanz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jsanz/32/53734_2.png) [@jsanz](https://discuss.elastic.co/u/jsanz)
#### Post date: [February 9, 2024, 9:51am UTC](https://discuss.elastic.co/t/metric-and-multi-option-controls/352807/4 "2024-02-09T09:51:58Z")

</div>

Glad it worked for you 💪

Yeah, please; the best practice is to do some research here for related questions, then open a new topic with as much detail as possible. Also, providing a reproducible example (as I did with the console commands) helps a lot in assisting you.

Mind also that at Elastic, engineers rotate to review the forums so it is very likely I won't be the person reading the new topics over the following days 🙂

Cheers.

---

<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: [March 8, 2024, 9:52am UTC](https://discuss.elastic.co/t/metric-and-multi-option-controls/352807/5 "2024-03-08T09:52:46Z")

</div>

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