Hi all,
Is it possible to calculate weighted averages in Grafana?
Basically I have a “grades” datasource in Elasticsearch, where each student has 4 grades per subject, and each subject has a weight.
I need to calculate the weighted average for each student.
I think I need to use Transformations, but I’m not sure which transformations would help me in this case.
I made a smaller version of the project using Docker and published it to GitHub here: GitHub - brunobastosg/grafana-elasticsearch-weighted-average-attempt
If anyone knows how to help and want to play with the data, just clone the repo and run docker compose up
.
EDIT: just found out that Elasticsearch can calculate the weighted averages (see below). Is there a way I can use this in Grafana?
POST /grades/_search
{
"size": 0,
"aggs": {
"students": {
"terms": {
"field": "studentName",
"size": 10
},
"aggs": {
"weighted_grade": {
"weighted_avg": {
"value": {
"field": "grade"
},
"weight": {
"field": "weight"
}
}
}
}
}
}
}