Design the Apache Superset dataset semantic layer: define metrics and calculated columns safely
Apache Superset’s dataset semantic layer is a lightweight metadata layer for defining reusable metrics and calculated columns in Explore. Put SQL that aggregates rows in a metric; put a row-level transformation in a calculated column. This distinction helps avoid double aggregation and misleading rates, while descriptions and certification make definitions easier for a team to find.
This guide follows Apache Superset 6.1.0 user documentation and its linked metrics guide, read on 2026-11-19. It covers the built-in dataset layer, not external semantic-layer connections or centralized warehouse modeling. SQL expressions and menus vary by database dialect, installation settings, and permissions.
What a dataset provides
Superset is not a warehouse for storing source data. It registers a physical database table or a virtual dataset defined by SQL so charts can query it, and attaches analysis metadata. Column settings such as temporal, filterable, dimensional, and date format clarify how fields appear in Explore.
The built-in layer offers two kinds of computed definition. A virtual metric is SQL that aggregates rows, such as revenue total or the share of rows meeting a condition. A virtual calculated column transforms a value or its presentation per row, such as a type cast, date conversion, or category bucket. Superset documentation allows and encourages aggregate functions in metrics but disallows them in calculated columns.
Metadata helps communicate meaning; it does not change the source schema or grant access. Superset 6.1.0 documentation says metrics can be certified. Certification does not automatically verify correctness or grant user access.
Choose a metric or a calculated column
| Need | Definition | Example and caution |
|---|---|---|
| Revenue total after filters and grouping | Metric | SUM(amount); an aggregate that charts recalculate by group. |
| Share of rows marked complete | Metric | SUM(CASE WHEN status = 'complete' THEN 1 ELSE 0 END) / COUNT(*). Check integer division and a zero denominator. |
| Convert each row’s date to a date type | Calculated column | Use a database-specific CAST or date conversion; it must be row-level. |
| Classify each row’s amount into a bucket | Calculated column | Use CASE and define boundaries, NULLs, negatives, and every edge case. |
Decide whether a rate means the mean of row-level rates or the aggregated numerator divided by the aggregated denominator. “Overall completion rate” usually means completed rows divided by eligible rows; it is not generally the mean or sum of group rates. Confirm whether values with mixed currencies or units can be added.
Define a metric
**Write the aggregation rule in plain language.** A name like “completion rate” is insufficient. Agree on eligible rows, completion status, time period, exclusions, numerator, and denominator.
**Inspect the dataset and source columns.** Check exposed columns, NULLs, duplicate rows, and possible join fanout. Verify how chart filters apply with the target database.
**Define aggregate values as metrics.** In dataset editing, enter a metric name, SQL expression, and description. The expression must match the connected SQL engine. Make conditions and casts explicit; cast division as needed to retain decimals.
**Keep calculated columns row-level.** Use them for date parsing, type conversion, label mapping, or buckets. Do not put aggregate functions there. For complex joins or transformations shared by many dashboards, a database view or upstream model may be clearer.
**Document meaning and ownership.** Record definition, unit, denominator, date basis, NULL/exception handling, and maintainer. Superset recommends metric descriptions. Where certification is available, use it to identify a team-trusted metric, not as a substitute for review.
Validate and check in a chart
In a development SQL Editor, run the expression over a representative period and filters. Superset follows the connected database’s dialect; do not copy SQL from another engine without checking it.
Compare with an independent reference query. Check totals and small groups, NULL/zero denominators, duplicate keys, boundary dates, negative values, types, and units.
Save the dataset and confirm the metric or calculated column appears in Explore. Change dimensions, time range, and filters, run the chart, and confirm the metric re-aggregates as intended.
Before changing a metric’s name or expression, identify dependent charts and dashboards. For breaking changes, add a new metric, check affected charts, and then migrate.
Keep names and descriptions clear. If a team relies on certified metrics, define separate ownership and review procedures.
Common failures and recovery
**A rate is 0 or 100 times too large:** distinguish integer division from number formatting. Verify the SQL result as a decimal and whether percent formatting multiplies by 100.
**Group totals differ from the overall value:** averages and rates are often non-additive; filters or NULL handling may differ. Inspect numerator and denominator by group.
**Chart values are duplicated:** inspect source grain and join cardinality. A metric or calculated column does not automatically solve fanout.
**The expression saves but fails at runtime:** check target-database syntax, column names, permissions, and types in SQL Editor. Examples are engine-dependent, not portable SQL.
**Other users cannot see the metric:** ask an administrator to check dataset/database permissions and roles. Names and certification are not access controls.
Metrics and calculated columns are a lightweight convenience layer. Where shared definitions matter, maintain complex models in the database or a central semantic model, and expose stable fields and metrics to Superset.
Sources
[Apache Superset 6.1.0: Creating Your First Dashboard — datasets and semantic layer](https://superset.apache.org/user-docs/6.1.0/using-superset/creating-your-first-dashboard/)
[Apache Superset 6.1.0: Feature Flags](https://superset.apache.org/admin-docs/6.1.0/configuration/feature-flags/)
[Apache Superset 6.1.0: Dataset API schema](https://superset.apache.org/developer-docs/6.1.0/api/schemas/dataset/)
[Preset: Using Metrics and Calculated Columns](https://docs.preset.io/docs/using-metrics-and-calculated-columns) (additional guide linked from Superset docs, updated 2022; validate SQL for your database)