A formula lets you calculate something a widget doesn't give you by default, such as a completion rate or the number of incomplete enrolments.
Formulas in Analytics work much like formulas in Excel. Instead of cell references such as A2, you use fields from your data model, such as [Number Of Enrolments]. Instead of working on one cell, each part of the formula is worked out for each row or group in your widget.
Before you start, read How widgets count and aggregate. Every formula is built from aggregations, so it helps to know how they work.
How to add a formula
- Open your widget in edit mode on your template dashboard.
- In Values, select + Add (or click an existing value to change it).
- Select the fx (function) icon to open the formula editor.
- Build your formula. You can type it, or select fields and functions from the panel on the right to add them.
- Select OK, then give the value a clear name, such as "Completion rate".
A few things to know:
- Field names go in square brackets, for example [Number Of Enrolments]. The easiest way to get them right is to select them from the "Data Browser" panel rather than typing.
- Every field needs an aggregation, such as SUM or COUNT. A formula that uses a field on its own won't work.
- Formulas use the widget's groups and filters. If your widget is split by Course Name, the formula is worked out once for each course.
Useful functions
| Function | What it does | Example |
|---|---|---|
| SUM | Adds up a number field | SUM([Number Of Enrolments]) |
| COUNT | Counts the different values in a field (Count Unique) | COUNT([User UUID]) |
| DUPCOUNT | Counts every row, including repeats (Count All) | DUPCOUNT([Enrolment Completion Date]) |
| AVG | Works out the average of a number field | AVG([Score]) |
| MIN / MAX | Finds the smallest or largest value | MAX([Enrolment Completion Date]) |
| RANK | Ranks each group by a value, such as the most completions | RANK(SUM([Number of Completed Enrolments])) |
Click on the "Functions" tab in the formula editor to see the full list of available functions.
Adding basic maths
You can combine these aggregations with + - * / and brackets, just like in Excel.
Example: incomplete enrolments
SUM([Number Of Enrolments]) - SUM([Number of Completed Enrolments])
This takes the number of completed enrolments away from the total number of enrolments.
Percentages
Example: completion rate by course
- Create a Pivot or Column chart widget.
- In Rows (or Categories), add Course Name.
- In Values, select + Add, then fx, and enter (copy and pasting may not work):
SUM([Number of Completed Enrolments]) / SUM([Number Of Enrolments])
- Select OK and name the value "Completion rate".
- Click the value, select Number format (or Format), and choose Percent. The result, such as 0.82, now shows as 82%.
Because the formula is worked out for each course, each row shows that course's own completion rate. The grand total is the completion rate across all courses, not the average of the rows.
Percentage of the total
To show each group's share of the whole, for example each location's share of all completions, you don't need a formula. Click the value and use the Contribution quick function. Each row then shows its percentage of the total.
Filtering inside a formula
Sometimes you want part of a formula to count only some rows, for example only overdue enrolments, while the rest of the formula counts everything. You can do this by adding a filter inside the formula. This works like COUNTIF or SUMIF in Excel.
The pattern is:
(aggregation, [field to filter on])
For example:
(SUM([Number Of Enrolments]), [Compliance - Status])
After you add the filter field, click it in the formula editor and choose the values to keep, such as Overdue. Only those enrolments are included in that part of the formula.
Example: percentage of enrolments that are overdue
(SUM([Number Of Enrolments]), [Compliance - Status]) / SUM([Number Of Enrolments])
Set the filter on Compliance - Status to Overdue, then format the value as Percent.
Ignoring a dashboard filter. If you want part of a formula to ignore a filter, wrap the field in ALL(). For example, ALL([Course Name]) makes that part ignore any Course Name filter, which is useful for showing a course against the overall figure.
Common mistakes
- Averaging percentages. AVG of a completion rate gives every course the same weight, however many enrolments it has. Divide the totals instead, as in the example above.
- Forgetting the aggregation. [Number Of Enrolments] / [Number Of Users] won't work. Each field needs SUM, COUNT or another function.
- Dividing measures that aren't linked. Both parts of the formula need to relate to the groups in your widget. If one part shows the same number on every row, the field you've grouped by probably isn't connected to that measure.
- Not checking the result. Test the formula on one course or person where you know the answer before you share the dashboard.
Next steps
- How widgets count and aggregate
- Titles, colours and formatting
- Setting up filters (primary, regular, background)
- Building widgets