DAX Synatx

DAX Syntax explained.

DAX (Data Analysis Expressions) is a formula language used to define custom calculations and logic in tools like Power BI, Excel Power Pivot, and SSAS Tabular.

Basic Structure of a DAX Expression

A DAX formula usually follows this structure:

NewName = DAX_Function(Arguments)
  • NewName: The name of the column, measure, or table you're creating.
  • =: Assignment operator.
  • DAX_Function: The DAX function or expression to perform the calculation.
  • Arguments: Input values, columns, tables, or nested functions.

Example (Measure)

Total Sales = SUM(Sales[Amount])
  • Total Sales: Name of the measure.
  • =: Assignment.
  • SUM: DAX function.
  • Sales[Amount]: Refers to the Amount column in the Sales table.

Key DAX Syntax Rules

RuleDescription
CommentsUse // for single-line comments
Case InsensitiveDAX is not case-sensitive (SUM, sum, Sum are all valid)
Tables and ColumnsUse TableName[ColumnName] to refer to a specific column
FunctionsSimilar to Excel, but tailored for data models
Text StringsEnclosed in double quotes ("Text")
VariablesUse VAR to declare variables and RETURN to output
Error HandlingUse functions like IFERROR, TRY, or IF for logic

Common Syntax Elements

ElementExamplePurpose
Column ReferenceSales[Revenue]Access a column value
Table ReferenceSalesAccess an entire table
Function CallSUM(Sales[Revenue])Aggregate values
VariableVAR x = 100Store temporary values
Logical TestIF(Sales[Revenue] > 1000, "High", "Low")Conditional logic

Example with Variables

Profit Margin = 
VAR Profit = SUM(Sales[Revenue]) - SUM(Sales[Cost])
VAR Margin = Profit / SUM(Sales[Revenue])
RETURN Margin
  • VAR stores intermediate steps.
  • RETURN outputs the final result.
  • This is easier to read, debug, and reuse than long inline formulas.
No questions available.