The layout it produces
PasteKit formats DAX with a built-in DAX tokenizer and printer that follows the conventions popularised by SQLBI’s DAX Formatter, so the output will look familiar to anyone who has read their books or articles:
- a function call that fits on one line is written as
SUM ( Sales[Amount] ), with spaces inside the parentheses - a call that does not fit puts one argument per line, indented, with the closing parenthesis lined up under the function name
VARandRETURNeach start a new line, and the expression afterRETURNis indented- long chains of
&&and||break before the operator, so each condition reads as a line - measure definitions keep their
Name =header on the first line, andName :=from Analysis Services projects is accepted too
Several measures pasted one per line are split apart with a blank line between them. Full queries starting with DEFINE or EVALUATE work as well, including the __DS0Core queries you get from Copy query in Performance Analyzer. Those arrive as one dense block, and indenting them is often the quickest way to see which filters a slow visual really sends.
Function case, width and shortcuts
Function case has two choices. UPPER (the default) writes function names and keywords in capitals: CALCULATE, SAMEPERIODLASTYEAR, VAR, RETURN, EVALUATE. As written leaves your casing alone, for when only whitespace should change. Table, column and measure names are never re-cased in either mode.
The toolbar indent sets how far arguments and RETURN bodies move in, and the line width decides when a call is too long to stay on one line. A narrower width produces the tall style that is easiest to review in Tabular Editor or a pull request on a PBIP project.
Use Ctrl/Cmd+Enter to format and Ctrl/Cmd+Shift+C to copy back into Power BI Desktop. DAX has no minify mode here, and Ctrl/Cmd+K lists every other command.
What formatting makes visible
Most DAX bugs are about context rather than syntax, and they are much easier to see once each argument has its own line. The classic one is wrapping a variable in CALCULATE:
Wrong Share =
VAR Sales = [Total Sales]
RETURN
DIVIDE ( Sales, CALCULATE ( Sales, REMOVEFILTERS ( 'Product' ) ) )
A variable is computed once, where it is defined, and its value does not change afterwards. The CALCULATE therefore has nothing to re-evaluate, and this measure returns 100% wherever there are sales. Put the measure inside it instead: CALCULATE ( [Total Sales], REMOVEFILTERS ( 'Product' ) ).
Two more worth checking while you read the output. A filter argument of FILTER ( Sales, ... ) iterates the whole table, where a column predicate such as 'Product'[Colour] = "Red" is usually enough and faster. And DIVIDE returns BLANK on a zero denominator, while the / operator returns infinity or NaN, so a stray / is worth a second look.
What it checks and what it cannot
The parser is deliberately lenient. DAX has hundreds of functions and new ones arrive in Power BI updates, so anything the printer does not recognise is passed through token by token. The only hard errors are the ones that make the expression unreadable: an unclosed string, 'quoted table', [column] reference or /* */ comment, or unbalanced brackets. Each is reported with its line and column.
Comments in all three DAX styles (//, -- and /* */) are kept. There is no model behind this page, so a misspelled column or a filter argument of the wrong type formats happily, and Power BI reports it when you commit the measure.
One limit to know about: semicolon list separators are kept, but a decimal comma is read as two numbers, so 0,5 is printed as 0, 5. Check those values if your model uses a locale with decimal commas.
The Power Query formatter handles the M side of the same report.
Examples
Year-over-year measure with variables
Each VAR gets its own line and the RETURN body is indented. The inner CALCULATE fits the width, so it stays on one line while the outer IF is split.
Sales YoY % = var CurrentSales=[Total Sales] var PriorSales=calculate([Total Sales],sameperiodlastyear('Date'[Date])) return if(not isblank(PriorSales),divide(CurrentSales-PriorSales,PriorSales))Sales YoY % =
VAR CurrentSales = [Total Sales]
VAR PriorSales =
CALCULATE ( [Total Sales], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )
RETURN
IF (
NOT ISBLANK ( PriorSales ),
DIVIDE ( CurrentSales - PriorSales, PriorSales )
)
Share of category with REMOVEFILTERS
One filter modifier per line shows exactly which filters CALCULATE removes and which it keeps, the part of this pattern people usually get wrong.
Category Share % = var CategorySales=calculate([Total Sales],removefilters('Product'[Subcategory]),values('Product'[Category])) return divide([Total Sales],CategorySales)Category Share % =
VAR CategorySales =
CALCULATE (
[Total Sales],
REMOVEFILTERS ( 'Product'[Subcategory] ),
VALUES ( 'Product'[Category] )
)
RETURN
DIVIDE ( [Total Sales], CategorySales )
Query copied from Performance Analyzer
The generated query separates into DEFINE variables, EVALUATE and ORDER BY, so the slicer filter and the TOPN window a visual requests can be read directly.
DEFINE VAR __DS0FilterTable = TREATAS({2026}, 'Date'[Year]) VAR __DS0Core = SUMMARIZECOLUMNS('Product'[Category], 'Customer'[Region], __DS0FilterTable, "Total_Sales", 'Sales'[Total Sales], "Margin__", 'Sales'[Margin %]) VAR __DS0PrimaryWindowed = TOPN(501, __DS0Core, [Total_Sales], 0, 'Product'[Category], 1, 'Customer'[Region], 1) EVALUATE __DS0PrimaryWindowed ORDER BY [Total_Sales] DESC, 'Product'[Category], 'Customer'[Region]DEFINE
VAR __DS0FilterTable = TREATAS ( { 2026 }, 'Date'[Year] )
VAR __DS0Core =
SUMMARIZECOLUMNS (
'Product'[Category],
'Customer'[Region],
__DS0FilterTable,
"Total_Sales",
'Sales'[Total Sales],
"Margin__",
'Sales'[Margin %]
)
VAR __DS0PrimaryWindowed =
TOPN (
501,
__DS0Core,
[Total_Sales],
0,
'Product'[Category],
1,
'Customer'[Region],
1
)
EVALUATE
__DS0PrimaryWindowed
ORDER BY [Total_Sales] DESC, 'Product'[Category], 'Customer'[Region]
Customer segments with SWITCH ( TRUE () )
Every argument of SWITCH takes its own line, so each condition is followed directly by the result it returns.
Customer Segment = var Spend=[Sales LTM] var Orders=[Orders LTM] return switch(true(),isblank(Spend),blank(),Spend>=50000&&Orders>=12,"Key account",Spend>=50000||Orders>=24,"Growth",Spend>=5000,"Standard","Occasional")Customer Segment =
VAR Spend = [Sales LTM]
VAR Orders = [Orders LTM]
RETURN
SWITCH (
TRUE (),
ISBLANK ( Spend ),
BLANK (),
Spend >= 50000 && Orders >= 12,
"Key account",
Spend >= 50000 || Orders >= 24,
"Growth",
Spend >= 5000,
"Standard",
"Occasional"
)
Common errors and how to fix them
| Error | Cause | Fix |
|---|---|---|
This '(' is never closed | A function call is missing its closing parenthesis, often at the very end of a long measure. The opposite mistake reports Unexpected ‘)’ instead. | Add the matching ‘)’. The position points at the opening bracket that has no partner, which is usually more use than where the measure ends. |
This [column] reference is never closed | A column or measure reference such as [Total Sales is missing its closing bracket, often after a hand edit. | Add the closing ]. A literal ] inside a name is written twice (]]). |
This string is never closed | A text literal is missing its closing double quote. | Add the closing “. To put a quote inside a DAX string, double it (”"). |
This quoted table name is never closed | A table name in single quotes, such as ‘Date’, is missing its closing apostrophe. | Close the quote. An apostrophe inside a table name is written twice (‘’). |
A single value for column 'Quantity' in table 'Sales' cannot be determined | Reported by Power BI, not by this page. A measure refers to a bare column where there is no row context to pick one value from. | Aggregate the column, or iterate: SUMX ( Sales, Sales[Quantity] * Sales[Net Price] ). For a column on a related table inside the iterator, use RELATED. |
Column 'Unt Price' in table 'Product' cannot be found or may not be used in this expression | Reported by Power BI, not by this page, which has no model to check against. The name is misspelled or the column is not in that table. | Correct the reference. A similar message without a table name, The value for ‘Sales Amnt’ cannot be determined, points to a measure name instead of a column. |
Frequently asked questions
Is this the same as daxformatter.com?
It follows the same layout conventions but is an independent formatter that runs in your browser. Results are very close for typical measures.
Can I format a DAX query from DAX Studio or Performance Analyzer?
Yes. EVALUATE, DEFINE, MEASURE and ORDER BY are recognised, so a query copied from Performance Analyzer or DAX Studio formats as readily as a single measure.
Will it change my column or measure names?
No. Function case only affects functions and keywords; table, column and measure references are left exactly as written.
Does it check that my DAX is valid?
Only for unbalanced brackets and unclosed quotes. It has no access to your model, so references and types are not checked.
Why does my CALCULATE have no effect on a variable?
A variable is evaluated once where it is defined, outside the filters the RETURN expression applies. Wrapping it in CALCULATE cannot re-evaluate it, so put the measure itself inside CALCULATE.
Does it work with semicolons as argument separators?
Semicolons between arguments are kept as written. A decimal comma is not understood, though: 0,5 comes out as 0, 5, so review those numbers before pasting the result back.