DAX Basics
Learn the syntax, structure, operators, and references used to write DAX formulas in Power BI.
DAX Basics
Before learning advanced DAX functions, it's important to understand how DAX formulas are written.
DAX formulas consist of expressions that reference tables, columns, measures, operators, and functions.
Understanding these building blocks makes writing calculations much easier.
DAX Formula Structure
Most DAX formulas follow this pattern:
Measure Name =
ExpressionExample:
Total Sales =
SUM(FactSales[SalesAmount])Everything to the left of the equals sign is the measure name.
Everything to the right is the expression that Power BI evaluates.
Tables and Columns
DAX references data using table and column names.
The syntax is:
TableName[ColumnName]Example:
SUM(FactSales[SalesAmount])Here:
FactSalesis the table.SalesAmountis the column.
Measures
Measures are referenced using square brackets only.
Example:
Profit Margin =
DIVIDE(
[Total Profit],
[Total Sales]
)Notice that measures do not include the table name.
Constants
DAX supports numeric, text, date, and Boolean constants.
Examples:
100
3.14
"North"
TRUE()
FALSE()
DATE(2026,1,1)Constants are often used inside calculations.
Arithmetic Operators
| Operator | Meaning |
|---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
^ | Exponent |
Example:
Total Cost =
SUM(Sales[Quantity]) * 25Comparison Operators
Comparison operators return TRUE or FALSE.
| Operator | Meaning |
|---|---|
= | Equal |
<> | Not Equal |
> | Greater Than |
< | Less Than |
>= | Greater Than or Equal |
<= | Less Than or Equal |
Example:
IF(
[Total Sales] > 100000,
"High",
"Low"
)Logical Operators
DAX also supports logical operations.
| Operator | Purpose |
|---|---|
&& | AND |
| ` | |
NOT() | NOT |
Example:
IF(
Sales[Quantity] > 10 &&
Sales[SalesAmount] > 500,
"Large Order",
"Standard Order"
)Comments
Single-line comments begin with two forward slashes.
// Calculate total sales
Total Sales =
SUM(FactSales[SalesAmount])Block comments can also be used.
/*
Revenue calculations
for monthly reporting
*/Comments improve readability and maintainability.
Functions
Functions perform calculations.
General syntax:
FUNCTION(argument1, argument2, ...)Example:
SUM(FactSales[SalesAmount])Here:
SUMis the function.FactSales[SalesAmount]is the argument.
Nesting Functions
Functions can be combined together.
Example:
Profit Margin =
DIVIDE(
SUM(FactSales[Profit]),
SUM(FactSales[SalesAmount])
)The SUM() functions execute before DIVIDE() returns the final result.
DAX Is Case Insensitive
These formulas are equivalent:
SUM(FactSales[SalesAmount])sum(FactSales[SalesAmount])However, using proper capitalization improves readability.
Best Practices
When writing DAX:
- Use descriptive measure names.
- Keep formulas readable.
- Format complex calculations across multiple lines.
- Reuse existing measures whenever possible.
- Add comments for complex business logic.
Readable DAX is easier to debug and maintain.
Next Steps
Continue learning: