AGENT SKILL

Power BI 查询设计

query-design

将 DAX 数据获取与 TypeScript 呈现相分离。指导何时使用 DAX、TypeScript 或 Vega-Lite 来进行聚合、总计行、FORMAT()、SELECTCOLUMNS、BLANK 处理、筛选、多粒度查询、交叉筛选与交叉高亮的子集/覆盖查询,以及格式字符串。

适用职业数据分析师
License 许可
MIT
所属仓库
microsoft/rayfin
最近更新
2026-11-12
Stars
★ 662
Forks
77

01 前言 Front Matter

name
query-design
description
Separates DAX data-fetching from TypeScript presentation. Guides when to use DAX vs. TypeScript vs. Vega-Lite for aggregation, total rows, FORMAT(), SELECTCOLUMNS, BLANK handling, filtering, multi-grain queries, cross-filtering and cross-highlight subset/overlay queries, and format strings.

02 资源文件 5

03 SKILL.md 正文

Query Design — Separation of Data and Presentation

DAX computes and fetches data. TypeScript shapes it for display. VegaVisual and DataGrid render it.

Aggregate in DAX to the visual's grain — never fetch lower-grain rows to roll up client-side. When a visual layout changes, only the TypeScript or spec layer should change — not the DAX query.

Responsibility Matrix

Concern Owner
Semantic measures (SUM, DISTINCTCOUNT, etc.) DAX
Filters and slicers DAX or TypeScript (see Filter Strategy)
Grouping grain (SUMMARIZECOLUMNS) DAX
Time intelligence (YTD, YoY) DAX
TopN / payload reduction DAX
Deterministic row ordering (ORDER BY) DAX (for debugging — not presentation sort)
Merging multiple result sets TypeScript
Server-provided grand totals (preferred, supports all aggregation types) DAX
DataGrid-computed grand totals DataGrid (alternative only for additive sum values or a count of fetched leaf rows)
Filling dimension gaps TypeScript (stitch dimension list into sparse results)
Reshaping (pivot, unpivot) TypeScript
Column display names columnMetadata in factory file
Number/date formatting columnMetadata.format / Vega-Lite spec
User-facing sort order TypeScript / Vega-Lite sort / DataGrid sort
Decorative labels, icons DataGrid cellRenderer or Vega-Lite condition
Axis titles, legends, color encoding Vega-Lite spec

Rules

Must

  • Aggregate in DAX to the visual's grain — never fetch lower-grain rows just to roll them up to that grain in TypeScript
  • One grain per .dax file (one EVALUATE per file); separate grains → separate files + separate useSemanticModelQuery calls
  • ORDER BY in DAX for stable, diffable results — not presentation sort
  • Same filters/measures across related split-grain queries to prevent drift

Prefer

  • SUMMARIZECOLUMNS for grouped aggregation — it also drops BLANK-measure rows, keeping payloads small
  • DAX's natural column names ('Table'[Column], [Measure]) mapped via columnMetadata.displayName
  • Raw typed values from DAX — format via columnMetadata.format or Vega-Lite, never FORMAT()
  • Model-defined format strings (from INFO.VIEW.MEASURES()) over invented ones
  • Multiple lightweight queries over one monolithic query
  • User-facing sort in TypeScript / Vega-Lite / DataGrid — never re-query for sort

Avoid

  • SELECTCOLUMNS solely for renaming — use columnMetadata.displayName instead
  • UNION to mix different grains (detail + total) — use separate queries
  • FORMAT() in DAX — converts to text, breaks sorting and charting
  • Converting BLANK to 0 / "" / "N/A" in DAX — causes result-set explosion
  • CONCATENATEX, UNICHAR, emoji prefixes — decorative text belongs in cellRenderer or Vega-Lite
  • Fetching all members of high-cardinality dimensions just to fill gaps

Decision Flowchart

Need to add something to the query result?
  |-- Calculation / aggregation / filter?
  |     -> DAX (measures, CALCULATE, SUMMARIZECOLUMNS)
  |-- Interactive filter the user controls?
  |     -> Low-cardinality: widen grain, filter in TypeScript or Vega-Lite transform
  |     -> High-cardinality: push filter to DAX, re-query
  |-- Adding a DataGrid grand total?
  |     -> DAX summary query: pass its one-row DataTable via grandTotals.data
  |     -> DataGrid-computed sum/count: set defaultAggregation, omit grandTotals.data
  |-- Merging datasets or adding other synthetic rows?
  |     -> Charts: pass multiple DataTables to VegaVisual, layer in spec
  |     -> Grids: append rows in TypeScript, style via cellRenderer
  |-- Renaming a column for display?
  |     -> columnMetadata in the factory file (displayName)
  |-- Formatting, labeling, or encoding?
  |     -> Vega-Lite spec or DataGrid cellRenderer
  |-- Decorating values (icons, status badges, null placeholders)?
  |     -> DataGrid cellRenderer or Vega-Lite condition encoding
  |-- Not sure?
        -> Does it change what the data *means* (filter, measure, grain)? -> DAX
           Does it change only how data is *rendered* (labels, icons, layout)? -> TypeScript / Vega-Lite spec / DataGrid cellRenderer
           Still unclear? -> Read the relevant reference above

Interactivity

Reports coordinate multiple visuals: a selection in one changes what the others show. Two distinct behaviors, with different data work behind them:

  • Cross-filtering — a selection in one visual constrains the data shown in another, removing or narrowing the non-matching rows from the target's view. The target shows less. Applying that constraint is a cost/cardinality tradeoff — widen the grain and filter client-side, or push the filter into DAX and re-query. See Filter strategy.
  • Cross-highlighting — a selection in one visual emphasizes the matching subset within another while the full context stays visible. The target keeps its baseline (dimmed) and draws the selected subset bright on top. The subset is a separate aggregation aligned to the baseline's grouping, measures, and row set — not a client-side filter of the baseline. See Highlight queries.

Both consume the predicate-based selection events the visual components emit (onInteraction). The components render only the DataTables they are handed; this skill produces those tables. For how a spec binds and layers multiple datasets, see the visuals skill's multi-data input reference.

Reference Materials

Read these when working on a specific topic:

  • Anti-patterns and corrections — Open when reviewing a query that uses UNION for totals, FORMAT(), SELECTCOLUMNS for renaming, CONCATENATEX/emoji decoration, BLANK-to-0 conversion, or GENERATE/CROSSJOIN for gap-filling.
  • Multi-grain patterns — Open when a single visualization needs data at two grains (e.g., bars + grand-total reference line, region detail + total row, monthly trend + YTD).
  • Filter strategy — Open when adding a user-controlled filter or implementing cross-filtering, and deciding whether to widen the grain (filter client-side) or push the filter into DAX (re-query on each change).
  • Highlight queries — Open when writing the "selected subset" overlay query for a cross-highlight visual: an aligned CALCULATETABLE / TREATAS query whose rows match the baseline.
  • Format strings — Open when picking a columnMetadata.format value, when a measure has a dynamic format string, or when formatting needs to flow into a Vega-Lite axis.

Integration with Sibling Skills

  • schema-discovery — Schema exploration; discover tables, columns, and relationships before writing queries.
  • dax-authoring — DAX syntax, query patterns, and testing workflow. Apply this skill's principles when deciding what DAX should compute.
  • visuals — Vega-Lite specs and DataGrid configuration. Push formatting and labels into specs, not DAX.

04 同仓库更多 Skills

microsoft
microsoft/rayfin

Rayfin 应用创建与入门

rayfin-getting-started

在启动或创建新的 Rayfin 应用时使用,或在出现 Rayfin 任务但尚未进入 Rayfin 项目时使用。它会通过 Rayfin CLI 带你进入项目,然后移交给项目内权威的、版本锁定的 rayfin 技能/文档,由它们负责所有项目内工作。触发词:构建 Rayfin 应用、启动 Rayfin 项目、创建新的 Rayfin 应用、create-rayfin、npm create @microsoft/rayfin、rayfin init、scaffold rayfin、rayfin CLI、rayfin template、universal app、awesome-rayfin gallery、get started with Rayfin。

软件开发工程师开发环境与工具链管理
★ 662
microsoft
microsoft/rayfin

数据可视化图表实现

visuals

当用户想要在项目中加入图表、图形、数据网格或其他数据可视化表示时使用。使用 VegaVisual 和 DataGrid 组件创建这些可视化,利用共享的 DataTable 输入、格式设置、主题和交互性。涵盖宿主应用消费的 onInteraction 选择/点击事件、用于分层叠加和参考线的命名多表数据输入,以及 Vega-Lite 原生选择。触发词:chart、graph、plot、dashboard、KPI、metric、trend、scorecard、data grid、visualize。

软件开发工程师前端开发与界面实现
★ 662
microsoft
microsoft/rayfin

Power BI 语义模型探查

schema-discovery

使用 DAX INFO 函数探索 Power BI 语义模型架构。包括渐进式元数据发现策略、范围估计,以及针对表、列、度量值和关系的缩小范围技巧。

数据分析师数据分析与报告
★ 662
microsoft
microsoft/rayfin

Universal App 函数能力开发

functions-capability

应用并构建 Universal App 的函数能力。用于可信的服务器端逻辑、密钥(secrets)、外部 API、自定义模型端点、已发布的 Fabric 数据智能体、Webhook 或特权操作。

软件开发工程师代码实现
★ 662
microsoft
microsoft/rayfin

Fabric 语义模型 DAX 查询

fabric-sdk

如何通过运行中的应用里的 Rayfin connectors 客户端查询 Fabric 数据。使用 getRayfinClient().connectors.<name>.executeQuery 对语义模型执行 DAX 查询,并使用 toQueryResult 规范化响应。

数据工程师数据分析与报告
★ 662
microsoft
microsoft/rayfin

Fabric 数据智能体调用

fabric-data-agent

通过 Rayfin 函数,使用应用程序认证和 MCP 流式 HTTP,从 Universal App 调用已发布的 Fabric 数据智能体。当请求中提到 Fabric 数据智能体、数据智能体 MCP 端点,或要求通过应用与受治理的 Fabric 数据对话时使用。

数据工程师智能体开发
★ 662