# I want to group data by tripid and find the max value of a field within this group

**URL:** <https://discuss.elastic.co/t/i-want-to-group-data-by-tripid-and-find-the-max-value-of-a-field-within-this-group/357332>\
**Category:** Kibana\
**Created:** [April 13, 2024, 6:15am UTC](https://discuss.elastic.co/t/i-want-to-group-data-by-tripid-and-find-the-max-value-of-a-field-within-this-group/357332 "2024-04-13T06:15:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anthony\_Wong](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anthony_wong/32/133495_2.png) [@Anthony\_Wong](https://discuss.elastic.co/u/Anthony_Wong)\
**Post date:** [April 13, 2024, 6:15am UTC](https://discuss.elastic.co/t/i-want-to-group-data-by-tripid-and-find-the-max-value-of-a-field-within-this-group/357332/1 "2024-04-13T06:15:35Z")

</div>

I am performing this SQL command  
SELECT MAX(DistanceTravel) as MaxTripDist, TripId FROM table.StatusMessage group by TripId;

Is there a way to show the max distance in a horizontal bar chart with the tripid as the x-axis and hte max distance on the y-axis?

---

<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:** [April 30, 2024, 1:22pm UTC](https://discuss.elastic.co/t/i-want-to-group-data-by-tripid-and-find-the-max-value-of-a-field-within-this-group/357332/2 "2024-04-30T13:22:24Z")

</div>

You can do that type of chart with Lens but using the graphical interface to aggregate by that filter and then get the maximum value of that other field.

On the following screenshot, using the Kibana Flights sample dataset, I group documents by the top values of the `Carrier` field and then get the maximum value of the `AvgTicketPrice` field.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/6/06596a0f432bb73fb8a72ee831c1d2bcc15e87fa.png)
