03.2Where should you store your measures?

You are going to create more and more measures. In Power BI, each one is stored in a table, without calculating “inside” that table. Here is what this storage changes, and how to organize it so you find your measures easily.

03.2.1Creating a measure

Power BI offers two ways to create a measure:

  • Select a table in the Data pane, then click the New measure button, on the Home tab. The measure is stored in the table you selected.
  • Right-click a table in the Data pane, then, in the menu that opens, choose New measure. The measure is stored in the table you clicked.

Either way, the formula bar opens with a temporary name, followed by the equal sign. You replace it with the name of the measure, you write the formula after the equal sign, then you commit it with the check mark of the formula bar.

03.2.2The result of a measure does not depend on its home table

When you create a measure, you are the one who chooses the table where it is stored. That is its home table. You can move it to another table at any time. The home table is first of all used to know where to show the measure in the Data pane. The list of fields only knows tables, so you do have to pick one.

The result, however, does not depend on this table. The “Revenue” measure returns 1,700,000, whether it is stored in Sales, in Customers or anywhere else.

Revenue = SUM( Sales[Amount] )
Power BI accepts this DAX foryes, Measureyes, Calculated columnno, Calculated tableno, Virtual table

Another clue confirms it. Two measures cannot share the same name, even when stored in two different tables.

03.2.3When the home table matters

Storage only matters in two cases.

Written with no argument, COUNTROWS counts the rows of the measure’s home table:

Number of Sales = COUNTROWS()
Power BI accepts this DAX foryes, Measureyes, Calculated columnno, Calculated tableno, Virtual table

Stored in Sales, this measure returns 12. Stored elsewhere, COUNTROWS counts the rows of another table.

Watch out!

Deleting a table also deletes the measures stored in it. If you replace the Sales table with a new version, the measures stored in it disappear along with it.

03.2.4Creating a table for your measures

To avoid these two traps and find all your measures in the same place, many professionals create a measures table, a table used only to store measures. To create it:

  • In Table view, on the Table tools tab, click the New table button. Power BI creates a new table and opens its formula in the formula bar.
  • Give the table a name in the formula, then commit it with the check mark of the formula bar. The new table appears in the Data pane, with one column.
  • Right-click the new table, then, in the menu that opens, New measure. Write the measure and commit it. It is stored in this table.
  • Right-click the column of the table, then, in the menu that opens, Hide in report view.

The table now shows only measures, and Power BI places it at the top of the Data pane. A measure already created elsewhere moves there with the Measure tools tab, then the Home table list.

Watch out!

A measures table does not contain the sales. A measure stored in it and written COUNTROWS() counts the rows of the measures table, not the sales.

03.2.5Storing measures in folders

When your measures run into the dozens, sort them into folders in the measures table. For example:

  • Performance, for the measures that track activity, like “Revenue,” “Number of Sales” or “Average Amount.”
  • Chart Titles, for the measures that write the title of a visual, like “Revenue for New York.”
  • Tooltips, for the measures shown only in the box that opens when you hover over a visual.

To store a measure in a folder:

  • In the bar on the left, click the Model view button.
  • Select the measure in the Data pane. To store several at once, select them while holding the Ctrl key.
  • In the Properties pane, type the name of the folder in the Display folder field, then press Enter.

The folder appears in the table, with its measures inside. It folds and unfolds with a click. A folder changes nothing in the calculation. It stores, like the home table does.

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

The measure Revenue = SUM( Sales[Amount] ) returns 1,700,000. You move it from the Sales table to a measures table. What does it return now?

Question 2

The measure Number of Sales = COUNTROWS() is stored in Sales and returns 12. You change its home table to Customers. What does it return now?

Question 3

The “Revenue” measure is stored in Sales. A new version of the table arrives, and you delete the old Sales to replace it. What happens to the measure?

Key takeaways
  • The result of a measure does not depend on its home table, unless COUNTROWS() is written with no argument. Apart from that case, the home table only serves to store the measure in the “Data” pane.
  • To find your measures in the same place, you can create a measures table. The New table button, in “Table” view, creates it, and a right-click on the table, then New measure, stores a measure in it.
  • Inside a table, measures can also be stored in folders, for example “Performance,” “Chart Titles” or “Tooltips.” You create a folder in “Model” view, with the “Display folder” field of the “Properties” pane.