Hi!
I need help with advanced formatting a list element in my dashboard. I have a data set that contains the number of completed questionnaires per topic and the target number of questionnaires. How do i write an arcade expression to calculate the progress as a percentage for each topic (Questionnaires completed/Target) and state whether the topic is 'outstanding' (highlighted in red) or 'achieved' (highlighted in green) based on the percentage.
Thank you 🙂
| Topic | Questionnaires completed | Target |
| 1 | 1 | 17 |
| 2 | 14 | 17 |
| 3 | 12 | 17 |
| 4 | 14 | 17 |
| 5 | 10 | 17 |
| 6 | 14 | 17 |
| 7 | 21 | 17 |
| 8 | 16 | 17 |
| 9 | 8 | 17 |
| 10 | 14 | 17 |
| 11 | 12 | 17 |
| 12 | 15 | 17 |
| 13 | 13 | 17 |
| 15 | 11 | 17 |
| 16 | 13 | 16 |
| 17 | 17 | 16 |
| 18 | 22 | 16 |
| 19 | 15 | 16 |
| 20 | 12 | 16 |
| 21 | 26 | 16 |
| 22 | 17 | 16 |
Is your example table the way the data itself is organized? What's the source table look like? Assuming your table is an accurate representation, here's what it could look like:
// calculating your percentage
var q_complete = $datapoint['questionnaires_completed']
var q_target = $datapoint['target']
var percentage = (q_complete / q_target) * 100
// color based on percentage; replace with whatever hex codes you like
var status_color = Iif(
percentage == 100,
'#ddffdd', // green
'#ffdddd' // red
)
// returning the values
return {
backgroundColor: status_color,
attributes: {
percentage
}
}
Then in your list item template, reference {expression/percentage} to pull in the percentage value.