# How to create an histogram with many aggregations on X axis and a formula on Y axis

**URL:** https://discuss.elastic.co/t/how-to-create-an-histogram-with-many-aggregations-on-x-axis-and-a-formula-on-y-axis/346518
**Category:** Kibana
**Tags:** visualisation
**Created:** [November 6, 2023, 11:29am UTC](https://discuss.elastic.co/t/how-to-create-an-histogram-with-many-aggregations-on-x-axis-and-a-formula-on-y-axis/346518 "2023-11-06T11:29:00Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![FIFI](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fifi/32/127266_2.png) [@FIFI](https://discuss.elastic.co/u/FIFI)
#### Post date: [November 6, 2023, 11:29am UTC](https://discuss.elastic.co/t/how-to-create-an-histogram-with-many-aggregations-on-x-axis-and-a-formula-on-y-axis/346518/1 "2023-11-06T11:29:00Z")

</div>

Hi,

Goal:  
I would like to create a histogram  
With two aggregations on X axis. One over terms. One over time.  
With one aggregation on Y axis. One over terms  
With a formula to compute value (using lens formula : sum(value, kql='data\_kind : "kind1" ')/sum(value, kql='data\_kind : "kind2" '))

Attempts:  
I tried with aggregation based visualization (succeed aggregation over X and Y axis, but didn't find any ways to apply formula)  
I tried with lens visualization (succeed aggregation over Y, and applied formula, but didn't find any ways to apply two aggregations over X)

Configuration  
elastic 7.17  
kibana 7.17

documents mapping

```auto
{
    @timestamp: date, # to aggregate over x 
    simulation_id: keyword, # to aggregate over x 

    field_to_aggregate_on_y: keyword, # to aggregate over y 
    data_kind: keyword, # used in lens formula 
    value: float
}

```

Any help ?

---

<div class="post-metadata">

### Author: ![Guillaume\_Dufrenne](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guillaume_dufrenne/32/103641_2.png) [@Guillaume\_Dufrenne](https://discuss.elastic.co/u/Guillaume_Dufrenne)
#### Post date: [November 7, 2023, 2:58pm UTC](https://discuss.elastic.co/t/how-to-create-an-histogram-with-many-aggregations-on-x-axis-and-a-formula-on-y-axis/346518/2 "2023-11-07T14:58:17Z")

</div>

Hello FiFi  
Are you trying to create an histogram on which  
The X axis represent the time,  
The Y axis represent the metric of "value"  
And you break down the metric by term ?

Can you elaborate on how you want to apply the aggregation over time ? What is the expected result ?

---

<div class="post-metadata">

### Author: ![FIFI](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fifi/32/127266_2.png) [@FIFI](https://discuss.elastic.co/u/FIFI)
#### Post date: [November 7, 2023, 3:14pm UTC](https://discuss.elastic.co/t/how-to-create-an-histogram-with-many-aggregations-on-x-axis-and-a-formula-on-y-axis/346518/3 "2023-11-07T15:14:34Z")

</div>

Hi Guillaume\_Dufrenne

Thank you for answering

I would expect something like the following histogram.

 ![Capture d’écran 2023-11-06 à 17.53.00](https://us1.discourse-cdn.com/elastic/original/3X/c/0/c08d2adeb37e1051c1f2f5b82c78a094448a1656.png)  
So  
we have two aggregations on X axis. One over time break down by terms.  
we have one aggregation on Y axis, by terms.

But  
In this histogram, the cells values are not correct.  
I would like to include a formula to compute the values of each cell.  
Which is the following in lens visualization  
`sum(value, kql='data_kind : "kind1" ')/sum(value, kql='data_kind : "kind2" ')`

For each bucket of aggregations (over X and Y), I would like two more aggregations to compute sum, and a third to compute the ratio. (which I can obtain using formula tab in lens visualization)

Thank you

---

<div class="post-metadata">

### Author: ![Jacqueline\_Jacquelot](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jacqueline_jacquelot/32/122429_2.png) [@Jacqueline\_Jacquelot](https://discuss.elastic.co/u/Jacqueline_Jacquelot)
#### Post date: [November 9, 2023, 2:35pm UTC](https://discuss.elastic.co/t/how-to-create-an-histogram-with-many-aggregations-on-x-axis-and-a-formula-on-y-axis/346518/5 "2023-11-09T14:35:03Z")

</div>

Hi FIFI

[_ **According to your documentation** _](https://www.elastic.co/guide/en/kibana/7.17/add-aggregation-based-visualization-panels.html), that this is not possible.  
You have to switch to Tableau.

---

<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: [December 7, 2023, 2:35pm UTC](https://discuss.elastic.co/t/how-to-create-an-histogram-with-many-aggregations-on-x-axis-and-a-formula-on-y-axis/346518/6 "2023-12-07T14:35:58Z")

</div>

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