Actual vs target in DAX: variance, % and status

The DAX pattern behind every KPI, actual, target, variance, variance %, attainment and status, targets stored per month and region with TREATAS, targets at a daily grain, year to date against target, KPIs where lower is better, and showing it with conditional formatting and the KPI visual.

Short answer: every KPI needs five measures: Actual, Target, Variance (Actual - Target), Variance % (DIVIDE ( Variance, Target )) and Status (on target or not, aware of whether higher or lower is better). Targets usually come per month and region, coarser than the facts: keep them in their own table and apply the report's filters to it with TREATAS, so the target follows slicers without a many-to-many relationship. Year to date works the same with DATESYTD on both.

Get this pattern right once and every KPI page (sales, costs, OTIF, churn) reuses it.

What do the measures return?

MonthActualTargetVarianceVariance %Status
Jan212200+12+6.0%On target
Feb188200-12-6.0%Below
Mar236220+16+7.3%On target
Apr205220-15-6.8%Below
Total841840+1+0.1%On target
Revenue against target, by month
  • Actual
  • Target
050100150200250050100150200250JanFebMarApr
Actual and target (thousands)

How do you write them?

Actual = SUM ( Sales[Amount] )

Target =
CALCULATE (
    SUM ( Targets[Amount] ),
    TREATAS ( VALUES ( 'Date'[Year Month] ), Targets[Year Month] ),
    TREATAS ( VALUES ( Region[Region] ), Targets[Region] )
)

Variance = [Actual] - [Target]

Variance % = DIVIDE ( [Variance], [Target] )

Attainment % = DIVIDE ( [Actual], [Target] )

Status =
SWITCH (
    TRUE (),
    ISBLANK ( [Target] ), BLANK (),
    [Actual] >= [Target], "On target",
    [Attainment %] >= 0.95, "Close",
    "Below"
)

The Targets table has one row per Year Month and Region. TREATAS passes the selected months and regions from the report to it. If targets have a column the facts do not (a product line, say), add a third TREATAS from that dimension.

What if the report shows days or weeks?

A monthly target shown per day must be split. The simplest is even by day:

Target (daily) =
SUMX (
    VALUES ( 'Date'[Date] ),
    VAR M = CALCULATE ( SELECTEDVALUE ( 'Date'[Year Month] ) )
    VAR DaysInMonth = CALCULATE ( COUNTROWS ( 'Date' ), ALL ( 'Date' ), 'Date'[Year Month] = M )
    RETURN DIVIDE ( CALCULATE ( [Target] ), DaysInMonth )
)

For seasonal businesses, weight by working days or by last year's daily share instead of even days.

How do you compare year to date?

Actual YTD = CALCULATE ( [Actual], DATESYTD ( 'Date'[Date] ) )
Target YTD = CALCULATE ( [Target], DATESYTD ( 'Date'[Date] ) )
Variance YTD % = DIVIDE ( [Actual YTD] - [Target YTD], [Target YTD] )

-- the full-year target, for "how far are we"
Target FY = CALCULATE ( [Target], ALL ( 'Date' ), VALUES ( 'Date'[Year] ) )

Mid-year, compare YTD actual with YTD target, not with the full-year target. See YTD, QTD and MTD.

What if lower is better?

For costs, defects, churn or delivery days, below target is good. Put the direction in one place:

Cost Variance % = DIVIDE ( [Cost] - [Cost Target], [Cost Target] )

Cost Status = IF ( [Cost] <= [Cost Target], "On target", "Over" )

-- a "good is positive" variance for colouring all KPIs alike
Cost Variance Good = -[Cost Variance %]

The KPI visual has a direction under Trend axis (high is good or low is good) for the same reason.

How do you show it?

  • Table or matrix: Variance % with conditional formatting (green above 0, red below), or an icon from Status.
  • KPI visual: Actual as value, Month as trend axis, Target as target.
  • Combo chart: Actual as columns, Target as a line (above).
  • Bullet-style bar: bars of Actual with a target marker, as a custom visual.

What goes wrong?

  • A relationship from Targets to Date by month. The Date table has many rows per month, so it becomes many-to-many; TREATAS or a Month dimension avoids it.
  • Target totals by summing the wrong grain. If targets repeat per product, SUM doubles them; store targets at one grain.
  • Variance % on tiny targets. +400% on a target of 1 dominates the colours; show variance in amounts too.
  • Mixed directions. Green for "up" on costs is red in reality; handle direction per KPI.

Where can you check this?

Where do you start?

Load your targets as a table at month and region grain and add the five measures. Then budget variance applies the same pattern to costs.

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.