Every KPI once, with measures and calculation groups

Define each KPI as one measure in the semantic model, and add year to date, last year and the change for all of them at once with one calculation group in Power BI.

Short answer: write each KPI exactly once, as a measure in the semantic model with a description and a format. Then add one calculation group with items for current, year to date, last year and the change. Each item uses SELECTEDMEASURE(), so it works for every KPI: ten KPIs need ten measures plus four items, not fifty measures.

When each report builds its own revenue, two reports show two numbers for the same month, and a meeting starts with an argument about whose is right. When every KPI also needs a year-to-date and a last-year version, the measure list grows five times over, and one fix has to be made five times.

What does the model hold?

KPIYou writeThe group adds
Revenueone measureYTD, PY, Change %
Ordersone measureYTD, PY, Change %
Average orderone measureYTD, PY, Change %
Revenue YTD, Orders PY, ...nine copiesno longer needed
Three KPIs, four time views: three measures and one group instead of twelve measures

How do you write the measures?

One measure per KPI, named the way the business says it. Ratios divide two measures instead of repeating their logic:

Revenue = SUM ( Sales[Amount] )

Orders = DISTINCTCOUNT ( Sales[OrderID] )

Average order = DIVIDE ( [Revenue], [Orders] )

Give each one a description (it shows when someone points at the field) and a format string, and put them in display folders. The model is now the one place a KPI is defined.

How does the calculation group work?

  1. 1
    MeasureRevenue, Orders, Average order
  2. 2
    ItemCurrent, YTD, PY, Change %
  3. 3
    SELECTEDMEASURE()the measure in the visual, with the item's filter
  4. 4
    Visuala column per item, or a slicer
One calculation group serves every measure

Each item is a small DAX expression around whatever measure the visual uses:

-- Calculation group "Time", column "View"
Current   = SELECTEDMEASURE ()
YTD       = CALCULATE ( SELECTEDMEASURE (), DATESYTD ( 'Date'[Date] ) )
PY        = CALCULATE ( SELECTEDMEASURE (), SAMEPERIODLASTYEAR ( 'Date'[Date] ) )
Change %  =
VAR Now  = SELECTEDMEASURE ()
VAR Then = CALCULATE ( SELECTEDMEASURE (), SAMEPERIODLASTYEAR ( 'Date'[Date] ) )
RETURN DIVIDE ( Now - Then, Then )

In Power BI Desktop, create it in Model view with Calculation group; external tools such as Tabular Editor work too. Put the group's column on the columns of a matrix and every KPI on the rows shows all four views.

Change % should show as a percentage even when the KPI is a currency. A dynamic format string on that item does it: set its format to "0.0%", and leave the others on SELECTEDMEASUREFORMATSTRING () so they keep the measure's own format.

What goes wrong?

  • Implicit measures stop working. Adding a calculation group turns on Discourage implicit measures, so dragging a raw column into a visual no longer sums it. That is the point: every number comes from a measure.
  • No date table. DATESYTD and SAMEPERIODLASTYEAR need a proper date table, marked as one, with a row for every day. Without it the time items return blanks or wrong numbers.
  • Items applied to the wrong measures. A ratio like Average order is fine, but a measure that already has its own time logic gets it twice. Keep time logic only in the group.

Where can you check this?

Where do you start?

The open course DAX measures that add up starts with measures instead of columns, then CALCULATE and the date table these items need. For the KPIs themselves, with their formulas in DAX, SQL and Excel, KPI Atlas has 455 of them. The pattern sits on the map of my work.

Keep reading

More from the blog.

Every post

Next

Building this? Say hello.

A question about this post, a pattern you would build differently, or the next thing you want written out: Behnia reads every message.