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.
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
- 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. - 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.
- Ranks a whole model dump by measure weight, so review happens on the three measures that matter instead of all sixty.
- 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:
DIVIDEabsorbs zero denominators, capture the outer row in aVARinstead ofEARLIER, drop the dead variable. No "consider refactoring for readability" hedges. - CI gates on what code review misses.
dxa lintexits 1 on any finding;--sariffiles 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
VARbindings 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
.xxmodel, 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)
CALCULATEinside a row iterator (SUMX,AVERAGEX, …)- Three or more nested
IFcalls (→SWITCH(TRUE(), …)) - Raw
/division (→DIVIDE, which absorbs zero denominators) = BLANK()comparisons (→ISBLANK)- Bare
ALL(table)as a filter eraser (→REMOVEFILTERS) &concatenation insideCONCATENATEXEARLIER(...)(→ capture the outer row withVAR)ALL/FILTER(ALL(...))as an aggregate's first argument (→ boolean filters inCALCULATE)IFERRORoverreach (→ explicit error contracts)HASONEVALUE+VALUESpairs (→SELECTEDVALUE)- Lowercase function calls (→ UPPERCASE form)
- Nested row iterators (→
VARcapture of the outer step) SWITCHwithout a default (→ explicit else argument)- Single-column row iterator (→ plain
SUM/AVERAGE/COUNT/MIN/MAX) ABS(...)against an impossible bound (→ sign check / drop the condition)IF(cond, TRUE(), FALSE())(→cond; inverted order →NOT cond)FILTER(...)as an aggregate's first argument (→ the filter condition inCALCULATE)CALCULATE(CALCULATE(...))(→ merge both filter lists into oneCALCULATE)COUNTROWS(VALUES(col))/COUNTROWS(DISTINCT(col))(→DISTINCTCOUNT(col))IF(ISBLANK(x), y, x)(→COALESCE(x, y); special case for BLANK() yes/else branches)SUMMARIZEwith a computed argument (→ group withSUMMARIZE, compute withADDCOLUMNS)IF(ISERROR(x), y, x)(→IFERROR(x, y))AND(...)as aCALCULATEfilter argument (→ one filter argument per conjunct)- A
VARnever referenced beforeRETURN(→ drop it or use it) COUNTROWS(t) = 0(→ISEMPTY(t);<> 0/> 0→NOT(ISEMPTY(t)))NOT(NOT(x))(→x; the double wrapper cancels)[flag] = TRUE()(→ the column itself;= FALSE()→NOT col)DISTINCTCOUNT(VALUES(col))(→DISTINCTCOUNT(col))IF(cond, x, x)(→x; the predicate computes for nothing)SUMX(t, k)with a constant (→COUNTROWS(t) * k)[x] <> BLANK()(→NOT(ISBLANK(x)))TRIM(TRIM(x))(→TRIM(x); one call is all it takes)FILTER(t, TRUE())(→t; the predicate keeps every row)x * 1,1 * x,x / 1(→ drop the operation;* 1// 1hold for blanks;+ 0is the zero-forcing idiom and is not flagged)UPPER(UPPER(x)),ABS(ABS(x)),INT(INT(x))(→ one call suffices)COUNTX(t, k)with a constant (→COUNTROWS(t))POWER(x, 1)(→x),POWER(x, 0)(→1), and the^formsOR(TRUE(), x)(→TRUE()),AND(FALSE(), x)(→FALSE())COALESCE(x, BLANK())andCOALESCE(x)(→ drop the trailing blank / the call)IF(c, …IF(c,…)…)in-branch (→ collapse the nesting)IF(TRUE(), x, y)(→x) andIF(FALSE(), x, y)(→y)COALESCE(x, x)(→ drop the duplicate fall-through)c && c,c || c,AND(c, c),OR(c, c)(→ keep one)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-deployfromdocs/) - Reference:
docs/CLI.md(flags, JSON shapes, exit codes), the rule index and reference indocs/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-daxis on PyPI (0.2.2), installed viapip 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)
| 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)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| 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 logRelease 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 logSecurity 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.
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 logA 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.