Does Apache Superset support Weighted Averages?
Asked Answered
M

1

7

I'm trying to use Apache Superset to create a dashboard that will display the average rate of X/Y at different entities such that the time grain can be changed on the fly. However, all I have available as raw data is daily totals of X and Y for the entities in question.

It would be simple to do if I could just get a line chart that displayed sum(X)/sum(Y) as its own metric, where the sum range would change with the time grain, but that doesn't seem to be supported.

Creating a function in SQLAlchemy that calculates the daily rates and then uses that as the raw data is also an insufficient solution, since taking the average of that over different time ranges would not be properly weighted.

Is there a workaround I'm not seeing? Is there a way to use Druid or some other tool to make displaying a quotient over a variable range possible?

My current best solution is to just set up different charts for each time grain size (day, month, quarter, year), but that's extremely inelegant and I'm hoping to do better.

Mane answered 21/7, 2020 at 15:50 Comment(0)
G
4

There are multiple ways to do this, one is using the Metric editor as shown bellow, in this case the metric definition is stored as part of the chart.

metric editor

Another way is to define a metric in the "datasource editor", where the metric will be stored with the datasource definition, and become reusable for any chart using this datasource, as shown here

enter image description here

Side note: depending on the database you use, you may have to CAST from say an integer to a numeric type as I did in the example, or multiply by 100 in order to get a proper result that's useful.

Gaudreau answered 22/7, 2020 at 17:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.