Hi Ted, what does one of your documents look like? I imagine it would be something like this:
{
school: "A school name or ID",
grade: 9,
student: "A student name or ID",
days_enrolled: 304,
days_present: 139,
}
And then it sounds like you want to create two types of Bar Charts: one which has average attendance on the Y axis and school on the X axis, and another which has average attendance on the Y axis and grade broken down per school on the X axis.
You can use the Visualize app to do this, but first you need to add some information using our Scripted Fields feature. Visit Management > Index Patterns, and then click the "Scripted Fields" tab. Here you'll need to create a new Scripted Field. We want to use this scripted field to calculate the average attendance for each document for us. Name your field something which makes sense to you, and then specify the script to be something like this:
if (doc['days_enrolled'].value == 0) {
return 0;
}
return doc['days_present'].value / doc['days_enrolled'].value;
The first if condition will protect against a divide-by-zero error in the event a student hasn't enrolled for any duration of time. The final return value is the PR/EN average attendance you're looking for, but only per document.
Next we need to define a visualization which will use this scripted field to show us the average attendance per school and per grade within each school.
Go to the Visualize app and create a new Bart Chart. Under "Metrics" define your Y-Axis with an Aggregation of "Average" and select your scripted field from the Field dropdown. Under "Buckets", define your X-Axis with an Aggregation of "Terms" and select the "school" field (or whatever your school field is named) from the dropdown. Hit the play button at the top to create the visualization. You should now see a Bar Chart showing you the average attendance per school. You can change the Size value to show more or fewer schools.
Now you can change this to also show grades per school. Change the field for this X-Axis to "grade" (or the equivalent field in your documents). Then click the "Add sub-buckets" button, select "Split chart" and click the "Columns" button beneath the new split chart you've added. Set the Sub-aggregation to "Terms" and set Field to "school". Hit the play button again and you should now see the grades split up into each school.
Let me know if you need any more help!
Thanks,
CJ