GitHub user dosubot[bot] added a comment to the discussion: Formulas in Superset

<!-- Greeting -->
Hi @taobojlen! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the 
superset team.

<!-- Answer -->
Superset supports formula-based annotations on timeseries charts using mathjs, 
so you can overlay a formula (with time as the variable `x`) on your chart—for 
example, to show a trend or threshold line. However, Superset does not 
currently let you create new chart series from formulas directly in the chart 
UI, like combining two series to compute a percentage as you would in PostHog. 
To achieve calculations like "percentage of rows matching a filter over time," 
you typically need to define a new metric (using SQL or your dataset's 
expression builder) that computes this ratio, and then plot that metric as a 
series in your chart. 

There are also built-in options for showing contributions or percentages in 
some chart types, but these are not as flexible as free-form formulas. Formula 
annotations are for overlays, not for generating new data series from existing 
ones in the UI. For more details, see the [formula annotation 
implementation](https://github.com/apache/superset/blob/93583220a7aa4debeaf3fd4a6cade9f771ee8c2f/superset-frontend/src/explore/components/controls/AnnotationLayerControl/AnnotationLayer.jsx)
 and [how formulas are applied in timeseries 
charts](https://github.com/apache/superset/blob/93583220a7aa4debeaf3fd4a6cade9f771ee8c2f/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformers.ts).

If you want to dynamically filter your data, Superset does support applying 
extra filters to charts via URL parameters, which can help with ad hoc analysis 
but doesn't provide formula composition in the UI. 

Let me know if you want more details on defining metrics or using formula 
annotations!


<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*

---
<sup>How did I do? 
[Good](https://app.dosu.dev/response-feedback/6548b971-6b64-45fc-b26b-229861042508?feedback_type=great_response)
 | 
[Irrelevant](https://app.dosu.dev/response-feedback/6548b971-6b64-45fc-b26b-229861042508?feedback_type=irrelevant_answer)
 | 
[Incorrect](https://app.dosu.dev/response-feedback/6548b971-6b64-45fc-b26b-229861042508?feedback_type=incorrect_sources)
 | 
[Verbose](https://app.dosu.dev/response-feedback/6548b971-6b64-45fc-b26b-229861042508?feedback_type=too_verbose)
 | 
[Hallucination](https://app.dosu.dev/response-feedback/6548b971-6b64-45fc-b26b-229861042508?feedback_type=hallucination)
 | [Report 
🐛](https://app.dosu.dev/response-feedback/6548b971-6b64-45fc-b26b-229861042508?feedback_type=bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/6548b971-6b64-45fc-b26b-229861042508?feedback_type=other)</sup>&nbsp;&nbsp;[![Join
 
Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Sh
 are on 
X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/discussions/33842)

GitHub link: 
https://github.com/apache/superset/discussions/33842#discussioncomment-13532449

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: 
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to