Skip to main content

aibi-dax

dxa, a DAX expression analysis CLI: complexity metrics, anti-pattern detection and per-model ranking. Companion to aibi-toolkit: where the toolkit checks the model around your measures (naming, formats, hygiene), aibi-dax checks the expressions inside them.

CI Lint Python Types Ruff

Why this exists

A DAX measure is a formula inside a formula engine. The syntax is small, the semantics are deep, and most mistakes compile fine and return a wrong number quietly. The failures that hurt are the ones nobody sees in code review: an iterator that shadows the filter context, a DIVIDE missing where a raw / hides behind a passing test, a dead VAR nobody deletes, a BLANK where zero was expected.

That problem does not print itself in an error message, and it does not announce itself in a visual either. It shows up as a measure that is harder to review but still "works". aibi-dax reads the expression and reports what it sees: how complex it is, and which known ways of being wrong it trips on.

What it does

  1. Scores complexity with one number you can sort on: weight = tokens + 3·functions + 5·depth + 20·iterators. Weighted so an iterator costs more than a function costs more than a token, because row context is where DAX quietly goes wrong.
  2. Flags 44 documented anti-patterns, each with a fix hint and a reason it fires. AST-driven rules, not regex: comments are blanked before the rules see the text, and string literals never trip a rule that fires on structure.
  3. Ranks a whole model dump by measure weight, so review happens on the three measures that matter instead of all sixty.
  4. Fits CI with stable exit codes (0 clean, 1 findings, 2 usage error) and SARIF output for code scanning.

How to use it

Install from PyPI and check the binary works:

pip install aibi-dax
dxa --version

Or install from the source tree: pip install ..

Score one expression (the weight is the number you sort on):

$ dxa metrics "SUMX('Sales', CALCULATE([Amount]))"
tokens      9
lines       1
chars       34
functions   2
depth       2
iterators   1
weight      45

Lint one expression (exit 1 when anything is found, so set -e fails the job):

$ dxa lint "IF(a, 1, IF(b, 2, IF(c, 3, [D] / [E])))"
- 3 nested IF calls — SWITCH(TRUE(), ...) reads better and evaluates faster.
- Raw '/' division — use DIVIDE(num, den) to absorb zero-denominator errors.

Rank the heaviest measures in a model dump (the JSON shape the TMDL export produces, so one file feeds both tools). Point it at a file or pipe it via stdin:

dxa rank model.json --top 3
tmdlexport | python -c "import sys, json; print(json.dumps(...))" > model.json
dxa lint-model model.json --sarif > results.sarif
cat measure.dax | dxa lint --file -

Everything is also --json for your own tooling, and the exit codes are the contract: 0 clean or informational, 1 findings, 2 usage error.

How it helps

  • Review honestly reads real code. Rank sorts measures by weight, so the gnarly ones land in front of a reviewer instead of after the easy ones. Iterator-dense measures are where filter-context bugs live, and they are the ones the weight favors.
  • Findings are actionable. Every rule says what it saw, why it is usually wrong, and the rewrite: DIVIDE absorbs zero denominators, capture the outer row in a VAR instead of EARLIER, drop the dead variable. No "consider refactoring for readability" hedges.
  • CI gates on what code review misses. dxa lint exits 1 on any finding; --sarif files them in the Security tab of your host with the same rule ids as --list-rules. The docs site documents a GitHub Actions workflow for both paths.
  • The error semantics are taught, not memorized. Rules encode the BLANK-vs-zero traps, iterator shadowing and uninitialized VAR bindings directly; each rule message is a one-line refresher for why the pattern is wrong.

What it is not

  • Not a DAX evaluator. It never computes a result. It reads expressions with a recursive-descent parser and reports structural patterns. Behavior is checked by the tests and by your own runs, as with a linter for anything else.
  • Not tied to Power BI. Any DAX-flavored text parses, whether it came from an .xx model, TMDL exports or a notebook cell. Flag semantics come from DAX, not from a live server.
  • Not a style checker. It flags patterns that are wrong, risky or dead weight. It does not care about indentation, case of your own identifiers, or where you put your semicolons.
  • Not a substitute for evaluation and measurement. It cannot tell you the measure is slow on data, or that your cardinality is the problem, or that a visual refresh is the bottleneck. Those come from performance analyzer and the toolkit, not from this.

Commands

Command What it does
dxa metrics "EXPR" token/function/depth/iterator counts + weight (repeatable; --file PATH; --top N keeps the N heaviest)
dxa metrics "EXPR" --json the same as a JSON payload ({"results": …} for several expressions)
dxa rank model.json heaviest measures first (--top N, --table T any case, --min-weight W; - = stdin)
dxa lint "EXPR" anti-pattern findings for one expression (--rule R, --list-rules [--json], --file PATH, --sarif)
dxa explain [RULE] full documentation for one anti-pattern rule; no argument lists them all (--json)
dxa lint-model model.json findings across every measure (--table T any case, --rule R, --summary, --sarif; - = stdin)
dxa parse "EXPR" the recursive-descent AST, human or --json (--file PATH)
dxa --completions shell bash/zsh/fish tab-completion script, generated from the parser

Model dumps use the same JSON shape TMDL export produces (the shared schema of aibi-toolkit), so one file feeds both tools.

44 anti-pattern rules detected (click to expand)
  1. CALCULATE inside a row iterator (SUMX, AVERAGEX, …)
  2. Three or more nested IF calls (→ SWITCH(TRUE(), …))
  3. Raw / division (→ DIVIDE, which absorbs zero denominators)
  4. = BLANK() comparisons (→ ISBLANK)
  5. Bare ALL(table) as a filter eraser (→ REMOVEFILTERS)
  6. & concatenation inside CONCATENATEX
  7. EARLIER(...) (→ capture the outer row with VAR)
  8. ALL/FILTER(ALL(...)) as an aggregate's first argument (→ boolean filters in CALCULATE)
  9. IFERROR overreach (→ explicit error contracts)
  10. HASONEVALUE + VALUES pairs (→ SELECTEDVALUE)
  11. Lowercase function calls (→ UPPERCASE form)
  12. Nested row iterators (→ VAR capture of the outer step)
  13. SWITCH without a default (→ explicit else argument)
  14. Single-column row iterator (→ plain SUM/AVERAGE/COUNT/MIN/MAX)
  15. ABS(...) against an impossible bound (→ sign check / drop the condition)
  16. IF(cond, TRUE(), FALSE()) (→ cond; inverted order → NOT cond)
  17. FILTER(...) as an aggregate's first argument (→ the filter condition in CALCULATE)
  18. CALCULATE(CALCULATE(...)) (→ merge both filter lists into one CALCULATE)
  19. COUNTROWS(VALUES(col)) / COUNTROWS(DISTINCT(col)) (→ DISTINCTCOUNT(col))
  20. IF(ISBLANK(x), y, x) (→ COALESCE(x, y); special case for BLANK() yes/else branches)
  21. SUMMARIZE with a computed argument (→ group with SUMMARIZE, compute with ADDCOLUMNS)
  22. IF(ISERROR(x), y, x) (→ IFERROR(x, y))
  23. AND(...) as a CALCULATE filter argument (→ one filter argument per conjunct)
  24. A VAR never referenced before RETURN (→ drop it or use it)
  25. COUNTROWS(t) = 0 (→ ISEMPTY(t); <> 0 / > 0 → NOT(ISEMPTY(t)))
  26. NOT(NOT(x)) (→ x; the double wrapper cancels)
  27. [flag] = TRUE() (→ the column itself; = FALSE() → NOT col)
  28. DISTINCTCOUNT(VALUES(col)) (→ DISTINCTCOUNT(col))
  29. IF(cond, x, x) (→ x; the predicate computes for nothing)
  30. SUMX(t, k) with a constant (→ COUNTROWS(t) * k)
  31. [x] <> BLANK() (→ NOT(ISBLANK(x)))
  32. TRIM(TRIM(x)) (→ TRIM(x); one call is all it takes)
  33. FILTER(t, TRUE()) (→ t; the predicate keeps every row)
  34. x * 1, 1 * x, x / 1 (→ drop the operation; * 1 / / 1 hold for blanks; + 0 is the zero-forcing idiom and is not flagged)
  35. UPPER(UPPER(x)), ABS(ABS(x)), INT(INT(x)) (→ one call suffices)
  36. COUNTX(t, k) with a constant (→ COUNTROWS(t))
  37. POWER(x, 1) (→ x), POWER(x, 0) (→ 1), and the ^ forms
  38. OR(TRUE(), x) (→ TRUE()), AND(FALSE(), x) (→ FALSE())
  39. COALESCE(x, BLANK()) and COALESCE(x) (→ drop the trailing blank / the call)
  40. IF(c, …IF(c,…)…) in-branch (→ collapse the nesting)
  41. IF(TRUE(), x, y) (→ x) and IF(FALSE(), x, y) (→ y)
  42. COALESCE(x, x) (→ drop the duplicate fall-through)
  43. c && c, c || c, AND(c, c), OR(c, c) (→ keep one)
  44. SUMX(t, IF(c, 1, 0)) (→ COUNTROWS(FILTER(t, c)))

What the weight measures

weight = tokens + 3·functions + 5·depth + 20·iterators. It is not a style metric; it is a review effort estimate. A deep iterator nesting is the one thing you cannot eyeball, so it dominates the score.

Docs and support

  • Docs site: https://sourinrakshit-ai.github.io/aibi-dax/ (mkdocs gh-deploy from docs/)
  • Reference: docs/CLI.md (flags, JSON shapes, exit codes), the rule index and reference in docs/rules.md, a cookbook of before/after rewrites, and a CI integration page with a GitHub Actions SARIF workflow.
  • Issues: issue tracker. Before filing, run dxa lint "your expression" so the rule names match the report.
  • Status: aibi-dax is on PyPI (0.2.2), installed via pip install aibi-dax. Trusted publishing is set up with a pending publisher for this repo, so every release from here on ships the same way.

Development

pip install -e ".[dev]"
python3 -m pytest -q                     # tests (docs smoke tests replay the CLI fences)
python3 -m mypy --strict src/aibi_dax/   # full strict typing
python3 -m ruff check src/ tests/        # lint
python3 -m pytest --cov=src/aibi_dax --cov-fail-under=95 -q   # coverage floor is 95

The gates are documented in CONTRIBUTING.md, the issue list and the 44 rules live under the docs site, and the worked examples run as examples/bench_rules.py and friends.

MIT licensed. Roadmap lives in the issue tracker.

Metadata

Release files for aibi-dax 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aibi-dax 0.2.2
File Size Uploaded Provenance Actions
aibi_dax-0.2.2.tar.gz 64.4 kB With provenance Details for aibi_dax-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aibi-dax 0.2.2
File Interpreter ABI Platform Actions
aibi_dax-0.2.2-py3-none-any.whl Python 3 none any Details for aibi_dax-0.2.2-py3-none-any.whl

Total release size: 104.3 kB

Release files / aibi_dax-0.2.2.tar.gz

Download URL aibi_dax-0.2.2.tar.gz
Size 64.4 kB
Tags Source
SHA-256 checksum
How to use checksums
483a298f80cd7cf0d074b60939a6c7b42152f2029d8b2570e51569e03df1b4ef
BLAKE2b-256 checksum
How to use checksums
5eeead6ba38ca0a123fc721bf0e4b53ab1d9cf05d7d75f89af7c222cdf6f37d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / aibi_dax-0.2.2-py3-none-any.whl

Download URL aibi_dax-0.2.2-py3-none-any.whl
Size 39.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
80d2525fb6d7750df42917fb48d03ff9789d22156a590e38ac0cc1ee00e42c34
BLAKE2b-256 checksum
How to use checksums
2738ebc5483c080d1670cff8bd4f8bc82704f1c7fb135a87e58918d9fb3b38dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Security for aibi-dax 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for aibi_dax-0.2.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page