dax-sql

中文文档
0.1.5发布于 2026/11/03MITES Module零依赖构建来源已验证

A DAX to SQL compiler for Tabular (TMSL) semantic models, with DAX semantics; tested on DuckDB

原始使用文档

dax-sql

A DAX to SQL compiler for Power BI / Tabular semantic models: a DAX query in, one SQL SELECT out, with DAX's semantics. Tested on DuckDB against Power BI's own answers. No dependencies.

Initially written by N.S. Devaraj.

npm install dax-sql
import { createCompiler } from 'dax-sql';
import { tmslToModel } from 'dax-sql/formats/tmsl.js';   // or formats/ossie.js for Apache Ossie

const model = tmslToModel(JSON.parse(bimText));           // a model.bim
const dax = createCompiler(model, { tableSource: t => `read_parquet('data/${t.name}.parquet')` });

const { sql, columns } = dax.compile(`
  EVALUATE
  SUMMARIZECOLUMNS('Date'[Year], "Sales", [Sales Amount])
  ORDER BY 'Date'[Year]`);
// sql: one SELECT for the engine; columns: [{ name: 'Year', type: 'int', ... }, { name: 'Sales', ... }]
  • In: a semantic model as dax-sql's model object (DESIGN.md; formats/ reads one from a TMSL model.bim or an Apache Ossie model whose metrics are DAX or SQL), a DAX query or a SQL SELECT over the model, options (DESIGN.md); or any SQL with SELECTs over the model as relations in it.
  • Out: one SQL SELECT and its columns; for a statement, its SQL with each of them compiled in place.
  • Errors: SYNTAX, SEMANTIC, UNSUPPORTED.
  • Tested: against Power BI's own answers, in conformance/.

Not implemented

  • Object-level security, dynamic format strings, the window functions' reset argument, and anything not listed in DESIGN.md.
  • FORMAT is en-US only, with a constant pattern; model format strings are not applied.
  • DATEDIFF with WEEK counts Sunday week boundaries.

Departures from DAX, by design

  • Text is case-sensitive in grouping, DISTINCT, sorting (by code point, not culture) and relationships; comparisons, IN and table filters are not, as in DAX.
  • Text keeps its trailing spaces (Power BI drops them on load): "a " and "a" are two values, in grouping, filters, relationships and LEN. Trim them in the data if they matter.
  • A column that mixes numbers and text comes back as text.
  • IFERROR returns its first argument: SQL has no error values.
  • A query that reads one table only (VALUES(Customer[City]), a slicer's list) has no blank row, though fact rows have keys the table lacks: it is a plain SELECT DISTINCT.

版本与发布记录

dax-sql 共发布 7 个版本,首次发布于 2026/10/29;过去 12 个月发布了 7 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.5latest2026/11/03今天
0.1.42026/11/03今天
0.1.32026/10/313 天前
0.1.22026/10/295 天前
0.1.12026/10/295 天前
0.1.02026/10/295 天前

关于 dax-sql 的常见问题

dax-sql 是什么?

一个DAX到SQL的编译器,用于表格(TMSL)语义模型,具有DAX语义;在DuckDB上测试

如何安装 dax-sql?

在项目目录运行 npm install dax-sql,或使用 pnpm add / yarn add / bun add。

dax-sql 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/dax-sql 是否存在。

dax-sql 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

dax-sql 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

dax-sql 可以商用吗?

dax-sql 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

dax-sql 还在维护吗?

最新版本 0.1.5 发布于 2026/11/03(今天);至今共发布 7 个版本,其中过去 12 个月发布了 7 个;首次发布于 2026/10/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。