# Canvas data table top hit metric

**URL:** https://discuss.elastic.co/t/canvas-data-table-top-hit-metric/293995
**Category:** Kibana
**Tags:** canvas
**Created:** [January 11, 2022, 8:52am UTC](https://discuss.elastic.co/t/canvas-data-table-top-hit-metric/293995 "2022-01-11T08:52:33Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![hNiven](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hniven/32/94305_2.png) [@hNiven](https://discuss.elastic.co/u/hNiven)
#### Post date: [January 11, 2022, 8:52am UTC](https://discuss.elastic.co/t/canvas-data-table-top-hit-metric/293995/1 "2022-01-11T08:52:33Z")

</div>

Hi,

I am creating a data table in canvas and was wondering if it is possible to do something similar to the 'top hit' metric you can do in the visualization, but in the canvas data table?

For example I have a field called message and I am wanting to get only the last timestamp value of that field and not show any of the previous values.

---

<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: [January 11, 2022, 8:55am UTC](https://discuss.elastic.co/t/canvas-data-table-top-hit-metric/293995/2 "2022-01-11T08:55:41Z")

</div>

You can use something like this:

```auto
SELECT customer_gender, count(*), max(order_date) FROM "kibana_sample_data_ecommerce" GROUP BY customer_gender

```

---

<div class="post-metadata">

### Author: ![hNiven](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hniven/32/94305_2.png) [@hNiven](https://discuss.elastic.co/u/hNiven)
#### Post date: [January 11, 2022, 9:22am UTC](https://discuss.elastic.co/t/canvas-data-table-top-hit-metric/293995/3 "2022-01-11T09:22:12Z")

</div>

Thank you for the quick reply @flash1293

That has helped but I need to add another field to it called UID which is a unique value that helps track each case's message.

But when adding that into the data table, I now get all the values for the message field again and not just the last value for each case. This is what I have tried below:

```auto
"SELECT UID, message , max(\"@timestamp\") as timestamp FROM "index"  
  group by message, uniqueIdentifier"}

```

---

<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: [January 11, 2022, 2:46pm UTC](https://discuss.elastic.co/t/canvas-data-table-top-hit-metric/293995/4 "2022-01-11T14:46:25Z")

</div>

If there are multiple uids, which one do you want to show? If you don't want to group by it, then you have to pick, just like in regular SQL

---

<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: [February 8, 2022, 2:47pm UTC](https://discuss.elastic.co/t/canvas-data-table-top-hit-metric/293995/5 "2022-02-08T14:47:21Z")

</div>

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