跳到正文
Skillpedia
分析与电子表格6.2k · #14401

table-calculations

它能做什么

这项技能说明如何为 Lightdash 指标查询编写表计算。适合需要在查询结果之上进行比较、百分比或排名的分析人员。

适用场景

  • ✓当你需要 Lightdash 查询中某项占总数的比率或百分比时。
  • ✓当你想要结果的累计总额、移动平均或排名时。
  • ✓当你需要环比变化或每个分组中排名靠前的项目的时候。

技能链接

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

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/lightdash/lightdash/blob/main/packages/backend/src/ee/services/ai/skills/builtInSkills/table-calculations/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请在我的每月营收 Lightdash 查询中添加一列累计总额,以及一列与上个月相比的变化。”

每周 5 个新技能,1 分钟读完。

工作原理

这项技能说明表计算所使用的类似电子表格的公式语法。它展示如何引用已选字段和其他计算,以及如何使用百分比的格式选项。

技术内容(原始 SKILL.md)

作者在 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.

常见问题

表计算是 SQL 吗?

不是。它们使用类似电子表格的公式,作用于查询结果,而不是原始 SQL。

它们会改变分组吗?

不会。它们作用于结果,除非你要求,否则不会添加分组字段。

如何显示百分比?

使用百分比的格式选项,而不要乘以 100。

详情

作者的原始描述

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

repo: lightdash/lightdash

热度

GitHub 星标
6.2k
排名
#14401
许可证
—
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能