Calculate based on aggregation Metrics results

I am using kibana 4
I generated a table using kibana aggregation, it has two metrics: sum of profits, and count. How do I add another metric to calculate the average profit per count by doing profits.value / count.value ?

Hi Sharon,

If both profits and count are formatted as number fields, then you could create a scripted field under Management > Index Fields > Scripted Field tab. Your scripted field would calculate the profits / count per document, and then you could Metric Sum Aggregation for this field to display it as another column in the table.

Does this help?


CJ, I think in this case "count" is the document count, and Profits is the Sum of a field. So a scripted field can't work because each document represents a count of 1.

Sharon, I think you can get the average if you're OK with having it on another visualization (and then you could have your current one and this average one next to each other on a Dashboard).

Can you try something like this?

  1. Change your Metric from Count to Average and select your Profits field.
  2. Split Rows by your Country
  3. Split Rows again by your Region
  4. Save this as a new Visualization name "Avg Profits" and then add your existing visualization and this new one on a dashboard together. You might need to set the Order By for your metrics to Term and use the Country and Region to make it match your first chart.