02.4DAX writing rules

Before writing more formulas, here are the writing rules of DAX, and most of them are reassuring. Let’s start with how to refer to a table, a column or a measure. Then come the rules themselves. Some are strict, others leave you plenty of freedom.

02.4.1Referring to a table

A table is referred to by its name alone, without square brackets:

COUNTROWS( Sales )

COUNTROWS counts the rows of the Sales table. Its result is 12.

If the table name contains a space or a special character, surround it with single quotes, like 'Sales 2025' or 'Sales-Returns'. Power BI writes them itself when you pick the table from the list it suggests.

02.4.2Referring to a column

SUM( Sales[Amount] )

The table Sales, then the column [Amount].

To refer to a column, you write the name of its table, then the name of the column in square brackets. Sales[Amount] is the Amount column of the Sales table. This is called a . If the table name contains a space or a special character, its single quotes stay in front of the brackets: 'Sales 2025'[Amount].

When you add a column to a table with a formula, it is called a . You will see it later. In that case, you don’t necessarily need to write the table name in front of its columns. If Sales did not already have its Amount column, you could add it like this:

Amount = [Qty] * [Price]

Power BI already knows which table you are adding the column to, here Sales. So it understands that [Qty] and [Price] are the Qty and Price columns of Sales.

A function that goes through a table row by row, like FILTER for example, also accepts the name of a column of that table with no table name in front:

FILTER( Customers, [City] = "New York" )

The first argument of FILTER is the table to go through, here Customers. So Power BI understands that [City] is the City column of Customers. You will see why later.

A formula can build a table during its calculation, with FILTER or ADDCOLUMNS for example. This table does not show up in the Data pane, and it disappears as soon as the calculation is over. It is a .

You can add a column to a virtual table:

Best Customer Revenue = MAXX( ADDCOLUMNS( VALUES( Sales[Customer ID] ), "Total", [Revenue] ), [Total] )

ADDCOLUMNS adds a column named “Total” to the virtual table. This table has no name. So to refer to its column, you only write [Total], with no table name in front. No need, for now, to understand the whole formula.

02.4.3Referring to a measure

DIVIDE( [Revenue], [Sales Count] )

[Revenue] and [Sales Count], names alone in square brackets.

[Revenue] and [Sales Count] are , formulas already written that you reuse by their name. A measure is written in square brackets, with no table name in front. Power BI would also accept the name of its home table in front, like Sales[Revenue] if it is stored in Sales, but the usual practice is to keep the table name for columns. That way you tell a measure from a column at a glance.

02.4.4Reading a name in square brackets

When you see a name alone in square brackets, with no table name in front, there are several possibilities:

  • a measure, like [Revenue];
  • the column of a virtual table, created earlier in the same formula, like [Total];
  • in a calculated column, a column of the table you are adding the column to, like [Qty];
  • in a function that goes through a table, like FILTER for example, a column of that table, like [City].

To decide, look at the formula and at the place where it is written.

With a table name in front, like Sales[Amount], it is a column of that table.

02.4.5What you must respect

A DAX formula follows fixed rules. If one of them is not respected, Power BI shows an error under the formula bar. In each example, look only at the highlighted part:

The writing rules of DAX
The name of the measure, without brackets, then the equal signRevenue = SUM( Sales[Amount] )
A measure called in square bracketsRevenue in Thousands = [Revenue] / 1000
A comma between two argumentsDIVIDE( [Revenue], COUNTROWS( Sales ) )
A closing parenthesis for each opening oneCOUNTROWS( FILTER( Customers, Customers[City] = "New York" ) )
A text in straight double quotesCustomers[City] = "New York"
A number with no space, comma or quotesSales[Amount] > 100000
Decimals after a period[Revenue] * 0.2
Names copied exactly, down to the last characterSUM( Sales[Qty] )

02.4.6What does not matter

On other points, DAX is flexible. These differences change nothing in the result:

What does not matter in DAX
Upper or lower case in functions and namesRevenue = sum( sales[amount] )
SpacesRevenue = SUM ( Sales[Amount] )
Single quotes around a table nameRevenue = SUM( 'Sales'[Amount] )
In general, upper or lower case in a compared textCustomers[City] = "new york"
CommentsRevenue = SUM( Sales[Amount] ) // the revenue

Single quotes become required when a table name contains a space or a special character, like 'Sales-Returns'[Qty]. For a table named Sales 2025, you write 'Sales 2025'[Amount] in the formula.

With the = sign, DAX does not tell "New York" from "new york." A few functions, like EXACT, do tell upper from lower case.

Even though Power BI accepts all these ways of writing, keep the names as they are in the tables. The formula is easier to read again.

02.4.7Comments

A measure can contain comments, text that Power BI ignores. They explain the formula to whoever will read it again, you in six months or a colleague. In the formula bar, Power BI writes comments in green, so you can tell them from the rest of the measure at a glance. The examples below use the same green. DAX has three kinds of comments.

Two forward slashes start a comment that runs to the end of the line:

Revenue = SUM( Sales[Amount] ) // all sales

Two hyphens do exactly the same thing:

Revenue = SUM( Sales[Amount] ) -- all sales

A forward slash followed by an asterisk opens a comment, which closes with an asterisk followed by a forward slash. This comment can sit in the middle of a line, or spread over several lines:

Revenue = /* all sales */ SUM( Sales[Amount] )
Tip

To start a new line in the Power BI formula bar, hold Shift and press Enter. The Enter key alone commits the measure.

Watch out!

With two forward slashes or two hyphens, everything that follows on the same line is part of the comment, even a formula:

Revenue = // all sales SUM( Sales[Amount] )

Here, SUM is inside the comment. The measure has no formula left, and Power BI shows an error.

02.4.8Indentation

A long measure is hard to read on a single line. You can spread it over several lines, and shift each argument to the right. That is indentation. Like spaces, line breaks change nothing in the result. They are only there to help reading.

On a single line, you have to count the parentheses to know where each function ends:

Chicago Small Sales Revenue = CALCULATE( SUM( Sales[Amount] ), Customers[City] = "Chicago", Sales[Price] < 50000, Sales[Qty] < 10 )

Indented, the same measure shows at a glance the calculation, then each condition:

Chicago Small Sales Revenue = CALCULATE( SUM( Sales[Amount] ), Customers[City] = "Chicago", Sales[Price] < 50000, Sales[Qty] < 10 )

A simple rule is to put one argument per line, shifted four spaces under its function, and the closing parenthesis alone on its line, level with the function it closes.

To start a new line in the Power BI formula bar, hold Shift and press Enter. The Tab key shifts the line to the right.

Quiz

The questions often rely on the course tables. Keep them in view in their floating window, which you can move and enlarge.

Question 1

How do you write the Brand column of the Products table?

Question 2

What is a measure in DIVIDE( [Revenue], SUM( Sales[Qty] ) )?

Question 3

Three ways of writing the “Revenue” measure. Which one does Power BI reject?

Key takeaways
  • A table is referred to by its name alone, without square brackets, like Sales. If that name contains a space or a special character, surround it with single quotes, like 'Sales 2025' or 'Sales-Returns'.
  • A column is referred to by the name of its table, followed by its name in square brackets, like Sales[Amount].
  • A measure is referred to by its name alone in square brackets, like [Revenue].
  • A name alone in square brackets does not always refer to a measure. It can also refer to the column of a virtual table, a column of the table you add a calculated column to, or a column of the table a function like FILTER goes through.
  • A DAX formula follows fixed rules, like the measure in square brackets, a comma between arguments, text in double quotes, names copied exactly.
  • Upper or lower case in functions and names, spaces and comments change nothing in the result.
  • A comment starts with // or with -- and runs to the end of the line. Between /* and */, it can spread over several lines.