Skip to content
Skillpedia
Analysis & spreadsheets6.2k · #14401

table-calculations

What it does

This skill explains how to write table calculations for Lightdash metric queries. It is for analysts who need comparisons, percentages or rankings on top of query results.

When to use it

  • ✓When you need a ratio or percentage of total in a Lightdash query.
  • ✓When you want a running total, moving average or ranking of results.
  • ✓When you need a period-over-period change or the top items in each group.

Skill link

https://github.com/lightdash/lightdash/blob/main/packages/backend/src/ee/services/ai/skills/builtInSkills/table-calculations/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/lightdash/lightdash/blob/main/packages/backend/src/ee/services/ai/skills/builtInSkills/table-calculations/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute →

Example of what to ask your AI

“In my Lightdash query of monthly revenue, add a column with the running total and a column with the change from the previous month.”

5 new skills a week. 1 minute to read.

How it works

The skill explains the spreadsheet-style formula syntax used by table calculations. It shows how to reference selected fields and other calculations, and how to use the formatting options for percentages.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Table calculations

For run_metric_query, author queryConfig.tableCalculations as type formula. The input schema documents the syntax and required fields; use spreadsheet-like formulas, not raw SQL.

Calculations operate on query results after aggregation. Reference selected field IDs or other table calculation names. The names below are placeholders: replace them with the actual fields or calculations in your query. Do not add grouping dimensions unless the user requested that grain.

When to use them

  • Arithmetic across metrics: metric_a + metric_b, ratios metric_a / metric_b.
  • Aggregating already-aggregated metrics (e.g., average of monthly totals): AVG(metric).
  • Percent of total: m / SUM(m).
  • Period-over-period: (m - LAG(m, ORDER BY date)) / LAG(m, ORDER BY date).
  • Rankings: RANK(ORDER BY m DESC).
  • Running totals: RUNNING_TOTAL(m, ORDER BY date).
  • Trailing 3-period average: MOVING_AVG(m, 2, ORDER BY date). The second argument counts preceding rows; the current row is also included.
  • Top N per group: ROW_NUMBER(PARTITION BY group, ORDER BY m DESC), then filter on that calculation.

Use the schema's formatting options for ratios and percentage changes; do not multiply a fraction by 100 when using percent formatting.

FAQ

Are table calculations SQL?

No, they use spreadsheet-like formulas that work on the query results, not raw SQL.

Will they change the grouping?

No, they work on the results and do not add grouping fields unless you ask for them.

How do I show a percentage?

Use the formatting options for percentages instead of multiplying by 100.

Details

Original description by the author

Author formula table calculations for run_metric_query, including ratios, aggregate comparisons, windows and rankings.

repo: lightdash/lightdash

Popularity

GitHub stars
6.2k
Ranking position
#14401
License
—
Updated
11/2/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills