Stop 09 · Advanced DAX PatternsTopics · 9/10

Calculation Groups

Part of the Power BI Roadmap

In short

Ten measures times YTD, Previous Year and YoY % is thirty extra measures. A calculation group writes each time logic once and applies it to any measure you drop into the visual.

Calculation groups apply a reusable calculation, like YTD or Previous Year, to any measure, cutting down on duplicated measures. They can be created directly in Power BI Desktop's Model view.

The jaadu holds up a single magnifying lens and moves it across three different jars, each one looking bigger through the glass.

Think of it like this

One pair of reading glasses

You don't buy separate glasses for the newspaper, a novel and the menu card. One pair works on whatever you look at. A calculation item like "YTD" is a lens: put Sales, Profit or Orders under it and you get YTD of that measure.

Watch it happen

One calculation group, many measures

Time Calc (calculation group)
Current
FYTD
PY
YoY %

1/5The group appears in the model as a table with one column, Calculation, holding four items.

The big ideas

What you need to know

SELECTEDMEASURE ()

A placeholder for whichever measure the visual is showing. Write the logic once around it.

Built in Model view

In Power BI Desktop, Model view > Calculation group creates one. Tabular Editor also works.

Format strings per item

Items can set their own dynamic format string, so YoY % shows as a percentage while others stay in rupees.

Implicit measures turn off

Creating a calculation group disables implicit measures, so dragging a raw column no longer auto-sums. Write explicit measures.

See it in code

Walk through the code

dax
1-- Calculation group: Time Calc, column: Calculation2 3-- Item: Current4SELECTEDMEASURE ()5 6-- Item: FYTD7CALCULATE ( SELECTEDMEASURE (), DATESYTD ( 'Date'[Date], "3-31" ) )8 9-- Item: PY10CALCULATE ( SELECTEDMEASURE (), SAMEPERIODLASTYEAR ( 'Date'[Date] ) )11 12-- Item: YoY %   (format string expression: "0.0%")13VAR CurrentValue = SELECTEDMEASURE ()14VAR PreviousValue =15    CALCULATE ( SELECTEDMEASURE (), SAMEPERIODLASTYEAR ( 'Date'[Date] ) )16RETURN17    DIVIDE ( CurrentValue - PreviousValue, PreviousValue )

1/4The plain measure, so the matrix also shows the current value.

Four calculation items. Put Time Calc[Calculation] on matrix columns and any measures in Values.

Save yourself the pain

Common mistakes

Oops

Writing [Total Sales] inside a calculation item.

Do this instead

Use SELECTEDMEASURE () so the item works with every measure, not just one.

Oops

Forgetting the format string on percentage items.

Do this instead

Without it YoY % inherits the measure's format and may show as ₹0.12. Set a format string expression for that item.

Oops

Dragging raw columns into visuals after adding a calculation group.

Do this instead

Implicit measures are disabled. Create explicit measures like Total Sales = SUM ( Sales[Amount] ).

Your mission

Thirty measures in four lines

~30 min

Quick check

What does SELECTEDMEASURE () refer to inside a calculation item?

Go deeper

  1. 1Create a calculation group with Current, PY and YoY % items.
  2. 2Apply it to Total Sales and Total Profit in one matrix.
  3. 3Learn the SELECTEDMEASURE function used inside them.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge