Skip to main content

Comment Script

Preview Feature

Comment Script is a preview feature and is only available in the DAX Studio preview build. Its syntax and behavior may change before the final release.

Comment Script lets you embed DAX Studio commands in a .dax file. Every command starts with -->, so it remains a DAX comment and the file can still be opened or executed by other tools.

Commands can connect to a model, set query parameters, split a document into batches, control traces and cache state, export artifacts, and verify query results or performance. This makes a script useful both for an interactive tuning session and for repeatable command-line tests.

How scripts run

A script is divided into batches by GO. Within each batch, DAX Studio processes the commands, executes the DAX query, and then evaluates assertions and post-query actions. Batches run in order on the same connection.

--> CONNECT SERVER localhost\tabular
--> USE "Adventure Works"
--> PARAMETER @Year INT64 = 2025
--> CLEARCACHE
--> TRACE SERVERTIMINGS ON

EVALUATE
FILTER ( 'Date', 'Date'[Year] = @Year )

Commands do not have to appear in a particular order, but placing setup commands before the query makes the script easier to read.

Comparing two queries

The following script captures an original query, then checks that an optimized version returns the same rows and does not take more than 10% longer.

--> TEST "Sales YTD optimization"
--> BASELINE "original"
--> CLEARCACHE

EVALUATE
SUMMARIZECOLUMNS (
'Date'[Year],
"Sales", CALCULATE ( [Sales], DATESYTD ( 'Date'[Date] ) )
)
ORDER BY 'Date'[Year]

--> GO

--> CLEARCACHE
--> ASSERT TABLE BASELINE "original"
--> ASSERT DURATION <= BASELINE "original" * 1.1

EVALUATE
SUMMARIZECOLUMNS (
'Date'[Year],
"Sales", [Sales YTD]
)
ORDER BY 'Date'[Year]

Server Timings starts automatically when a baseline or performance assertion requires it.

Verifying expected results

Use an inline Markdown table to keep small expected result sets beside the query. Each table row starts with -->>, so it is also a valid DAX comment.

--> ASSERT TABLE UNORDERED
-->> | Color | ProductCount |
-->> |-------|--------------|
-->> | Red | 5 |
-->> | Blue | 3 |

EVALUATE
SUMMARIZECOLUMNS (
'Product'[Color],
"ProductCount", COUNTROWS ( 'Product' )
)

Commands

CommandPurpose
CONNECTConnect to a server, Power BI Desktop model, or SSDT workspace
USESelect a database on the current connection
PARAMETERSupply a query parameter value
SETDefine a reusable script variable
GOEnd a batch and optionally delay the next one
CLEARCACHEClear the model cache before a query
TRACEEnable or disable a trace
EXPORT METRICSExport VertiPaq Analyzer metrics
SHOWDisplay dependencies, metadata, diagrams, or metrics
ASSERTCheck row count or performance metrics
ASSERT TABLECompare query results with expected data
BASELINECapture results and timings for later comparison
PREVIOUSCompare with the preceding query batch
SAVEASSave the executed query or a DAX Studio package
TESTAssign a descriptive name to a test
RESULTSControl whether the results grid is shown

Script variables are expanded only in command arguments, not in the DAX query body. Syntax errors, missing baselines, failed variable expansion, and failed assertions are reported as script errors.