Compare a canvas KPI against a target measure - #9820
Open
dfliess wants to merge 1 commit into
Open
Conversation
A canvas KPI can only compare a measure with itself, over an earlier time
range. But a budget, a target or a forecast is a second measure, so there is
no way to render "revenue vs target" today, and those cards end up drawn by
hand as Vega custom charts.
`measure_comparisons` says which measure a KPI is compared against:
```yaml
kpi_grid:
metrics_view: sales
measures: [revenue]
measure_comparisons:
- measure: revenue
compare_to: target_revenue
comparison: [previous, percent_change]
```
The comparison query then asks for that measure over the same time range,
instead of the same measure over an earlier range. The result is stored under
the name of the first measure, so the existing rendering path does not change.
Each pair is a list item, because other canvas widgets already store
per-measure settings that way.
Both measures must belong to the same metrics view, and the reconciler checks
`compare_to`. An entry for a measure the grid no longer shows is ignored, and
not an error: removing a measure in the inspector leaves its entry behind, and
breaking the resource for that would leave a state nobody can fix from the UI,
since the inspector does not show this option.
It also works without a time dimension, which the time comparison does not.
For a percentage measure use `delta`, since Rill already hides
`percent_change` there, and `delta` gives the difference in points.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We wanted to show a measure next to its target in a canvas KPI, and we could not find a way to do it. If there is one and we missed it please let us know, feel free to close this.
What we found: a canvas KPI can only compare a measure with itself, over an earlier time range. But a budget, a target or a forecast is a second measure, so today there is no way to render "revenue vs target". We drew those cards by hand instead, as Vega custom charts, about 35 lines of positioned text per card. This PR is what we use now, in case it is useful to you too.
How it works: the comparison query asks for the other measure over the same time range. It does not ask for the same measure over an earlier range. The result is then stored under the name of the first measure, so
KPI.svelterenders it as before and we did not have to touch it.Things we were not sure about
measure_comparisons. We avoidedcomparison_measuresbecause that name already means something else in the codebase. Rename it if you prefer.delta, notpercent_change. Rill already hidespercent_changefor percentage measures.deltathen gives the difference in points. We wrote this in the docs instead of adding a special case.Some questions. We do not know Rill well enough to answer these ourselves.
Happy to rename things or rework it, and just as happy to keep it on our side if you do not want it.