Adding Rolling 12 Months to a Power BI model shouldn't be a big deal. But what if that model has forty KPIs, each with its own time comparisons? Suddenly, a small request can turn into a lot more work than expected.

So I wanted to put two approaches to the test: calculation groups and DAX UDFs. Not to see which one writes less DAX, but what happens when requirements change. I'll build both, introduce a few realistic changes, and see which one actually makes life easier for the developer maintaining it.

In this blog

  • Same results, different DAX. Does the approach really matter?
  • One rule changes. How much of the model needs fixing?
  • What happens when reusable logic meets exceptions?
  • Forty measures later, which approach actually saves us work?

Two Ways to Build the Same Solution

We'll use a simple sales model with a Date table and four base measures: Revenue, Cost, Units Sold, and Margin %. Each needs to support Current Year, Previous Year, and YoY% comparisons.

We'll start with four KPIs to keep the implementation easy to follow, then consider what happens when the same approach needs to support forty. The goal is to build two versions that produce the same calculations but structure the reusable logic differently. We'll use a continuous Date table, an active relationship to the sales data, and the same date selection for both approaches.

01
IMPLEMENTATION APPROACH

Calculation Groups

Let's create a calculation group called Time Comparison with three calculation items.

DAX Current Year
-- Keep the selected measure in its current filter context
SELECTEDMEASURE()
DAX Previous Year
-- Evaluate the selected measure one year earlier
CALCULATE(
    SELECTEDMEASURE(),
    DATEADD('Date'[Date], -1, YEAR)
)
DAX YoY% — Calculation Group
-- Evaluate the selected measure for the current period
VAR CY = SELECTEDMEASURE()
-- Evaluate the same measure for the previous year
VAR PY =
    CALCULATE(
        SELECTEDMEASURE(),
        DATEADD('Date'[Date], -1, YEAR)
    )
-- Calculate relative year-over-year growth
RETURN
    DIVIDE(CY - PY, PY)

The important part is SELECTEDMEASURE(). It allows the calculation group to transform whichever measure is being evaluated, without referencing Revenue, Cost, or Units Sold individually.

In the report, we can place the calculation group in a slicer or use its items as matrix columns. With four base measures and three calculation items, we can expose all twelve combinations through the calculation group without defining twelve individual measures.

ARCHITECTURAL
ASSESSMENT
Advantage

We define transformations once and apply them across multiple KPIs. Adding another measure doesn't require additional time-intelligence measures.

Trade-off

The active calculation item influences how a measure is evaluated. That keeps the model compact, but it also means we need to understand the calculation-group context when investigating results or handling exceptions.

02
IMPLEMENTATION APPROACH

DAX User-Defined Functions

Now let's build the same comparisons using DAX UDFs. Instead of applying transformations through a calculation group, we'll create reusable functions that accept a measure reference and evaluate it using our time-intelligence logic.

In Power BI Desktop, open DAX Query View and define the functions using DEFINE FUNCTION. After testing them, use Update model with changes to save them to the semantic model. Once saved, they can be called from regular measures.

We'll create two functions: PreviousYear and YoYGrowth.

DAX UDF PreviousYear Function
DEFINE
    /// Calculate the selected measure for the previous year
    FUNCTION PreviousYear =
        (MeasureExpr : MEASUREREF) =>
            -- Shift the measure's date context back one year
            CALCULATE(
                MeasureExpr,
                DATEADD('Date'[Date], -1, YEAR)
            )
DAX UDF YoYGrowth Function
DEFINE
    /// Calculate relative year-over-year growth
    FUNCTION YoYGrowth =
        (MeasureExpr : MEASUREREF) =>
            -- Evaluate the current period
            VAR CY = MeasureExpr
            -- Reuse the PreviousYear function
            VAR PY = PreviousYear(MeasureExpr)
            RETURN
                DIVIDE(CY - PY, PY)

These are function definitions, not measures. When testing them in DAX Query View, the query also needs an EVALUATE statement. The two functions can be defined together and saved to the model. Once they're available, we can create regular measures that call them.

DAX Calling the UDFs
-- Revenue comparisons
Revenue PY = PreviousYear([Revenue])
Revenue YoY% = YoYGrowth([Revenue])
-- Cost comparisons
Cost PY = PreviousYear([Cost])
Cost YoY% = YoYGrowth([Cost])
-- Repeat for Units Sold and Margin %

Notice the difference. The Previous Year logic exists in one function, and our YoY% function can reuse it. But we're still explicitly creating the measures that expose those calculations.

For four KPIs, that means four base measures and eight additional comparison measures. We can then use a field parameter or another selection mechanism to make the combinations available in the report.

ARCHITECTURAL
ASSESSMENT
Advantage

Shared calculations are defined centrally, can be composed from other functions, and are explicitly invoked wherever they're needed.

Trade-off

A reusable function doesn't automatically create every KPI and comparison combination. In this implementation, we still maintain the calling measures and the reporting selection.

Same Calculations, Different Structures

Before changing any requirements, we need to establish that both approaches are intended to produce the same results. Using Revenue as an example, the table below illustrates the expected output when both implementations are evaluated under identical date selections.

01 / EXPECTED RESULTS Same inputs. Same outputs.
Illustrative example
Comparison Calculation Group DAX UDF
Revenue CY €1,200,000 €1,200,000
Revenue PY €1,000,000 €1,000,000
Revenue YoY% 20.0% 20.0%

In an actual model, we'd repeat this check for Cost, Units Sold, and Margin %, including different date selections and periods spanning multiple months. Only after confirming matching results should we compare the maintenance effort. For now, let's look at what each implementation requires us to maintain.

02 / MODEL BASELINE What we're maintaining
Initial implementation
Component Calculation Groups DAX UDFs
Base measures 4 4
Reusable definitions 3 calculation items 2 functions
Additional comparison measures 0 8
Report selection Calculation group Field parameter or equivalent
Calculation application Selected measure Explicit function calls

These counts reflect the specific implementations we've built, including our decision to expose UDF comparisons through individual measures. They aren't universal requirements of DAX UDFs.

The difference is visible before we've changed a single requirement. Calculation groups keep the reporting model compact, while our UDF implementation makes the reusable logic explicit but requires additional calling measures. Neither tells us which approach will be easier to maintain. That only becomes clear when we start changing the rules.

↗ THE NEXT CHALLENGE
CHANGING REQUIREMENTS

But what happens when the business changes the rules? Will both approaches remain equally easy to maintain?

The Maintenance Test: Change, Extend, Add

Both implementations are in place. Now let's see what happens when the business comes back with three requests. First, change an existing comparison rule. Then, introduce Rolling 12 Months across every KPI. Finally, add another KPI that needs to support all our comparisons.

None of these requests is particularly unusual. The interesting question is how much of our existing implementation needs to change each time.

01
MAINTENANCE TEST

Test 1: Change the Previous Year Logic

The business wants comparisons to include only completed months. For example, if we're in October 2026, Current Year should cover January through September 2026, while Previous Year should cover January through September 2025.

This changes more than the Previous Year calculation. We also need to ensure that Current Year and YoY% use the same reporting window. Otherwise, we could end up comparing nine months of one year against ten months of another.

For this example, we'll use calendar-year-to-date periods and anchor the cutoff to TODAY(). That means the reporting window follows the current date rather than a date selected in a slicer.

APPROACH 01

With Calculation Groups

We need to update all three calculation items. The underlying KPI measures remain unchanged. First, Current Year needs to stop at the last completed month:

DAX Current Year Ā· Calculation Item
VAR LastCompletedMonth = EOMONTH(TODAY(), -1)
RETURN
    CALCULATE(
        SELECTEDMEASURE(),
        DATESBETWEEN(
            'Date'[Date],
            DATE(YEAR(LastCompletedMonth), 1, 1),
            LastCompletedMonth
        )
    )

Next, Previous Year uses the equivalent completed-month period from the year before:

DAX Previous Year Ā· Calculation Item
VAR LastCompletedMonth = EOMONTH(TODAY(), -1)
VAR PYCutoff = EDATE(LastCompletedMonth, -12)
RETURN
    CALCULATE(
        SELECTEDMEASURE(),
        DATESBETWEEN(
            'Date'[Date],
            DATE(YEAR(PYCutoff), 1, 1),
            PYCutoff
        )
    )

Finally, YoY% must evaluate both periods using the revised boundaries:

DAX YoY% Ā· Calculation Item
VAR Cutoff = EOMONTH(TODAY(), -1)
VAR PYCutoff = EDATE(Cutoff, -12)
VAR CY =
    CALCULATE(
        SELECTEDMEASURE(),
        DATESBETWEEN(
            'Date'[Date],
            DATE(YEAR(Cutoff), 1, 1),
            Cutoff
        )
    )
VAR PY =
    CALCULATE(
        SELECTEDMEASURE(),
        DATESBETWEEN(
            'Date'[Date],
            DATE(YEAR(PYCutoff), 1, 1),
            PYCutoff
        )
    )
RETURN
    DIVIDE(CY - PY, PY)

Three calculation items have changed, but the revised rules apply to all four KPIs without creating or modifying individual KPI measures.

APPROACH 02

With DAX UDFs

The UDF implementation needs the same completed-month logic. We can keep that logic reusable by introducing a CurrentYear function and updating PreviousYear and YoYGrowth.

DAX UDF CurrentYear Ā· DAX UDF
DEFINE
    FUNCTION CurrentYear =
        (MeasureExpr : MEASUREREF) =>
            VAR Cutoff = EOMONTH(TODAY(), -1)
            RETURN
                CALCULATE(
                    MeasureExpr,
                    DATESBETWEEN(
                        'Date'[Date],
                        DATE(YEAR(Cutoff), 1, 1),
                        Cutoff
                    )
                )

We also revise PreviousYear to use the equivalent completed-month window:

DAX UDF PreviousYear Ā· DAX UDF
DEFINE
    FUNCTION PreviousYear =
        (MeasureExpr : MEASUREREF) =>
            VAR Cutoff = EOMONTH(TODAY(), -1)
            VAR PYCutoff = EDATE(Cutoff, -12)
            RETURN
                CALCULATE(
                    MeasureExpr,
                    DATESBETWEEN(
                        'Date'[Date],
                        DATE(YEAR(PYCutoff), 1, 1),
                        PYCutoff
                    )
                )

Now YoYGrowth can reuse both functions rather than maintaining its own date-window expressions:

DAX UDF YoYGrowth Ā· DAX UDF
DEFINE
    FUNCTION YoYGrowth =
        (MeasureExpr : MEASUREREF) =>
            VAR CY = CurrentYear(MeasureExpr)
            VAR PY = PreviousYear(MeasureExpr)
            RETURN
                DIVIDE(CY - PY, PY)

The comparison measures that already call PreviousYear and YoYGrowth can remain unchanged. Their definitions now use the revised functions.

However, if we want Current Year to appear as a separate completed-month comparison in the report, we must also expose CurrentYear through calling measures and update the report selection. That adds four more measures in our implementation.

āœ“ TEST 01 Ā· THE FINDING

Both approaches can apply the revised comparison logic across all four KPIs without rewriting the underlying measures.

In our calculation-group implementation, three existing calculation items change. In the UDF implementation, we add one function, revise two existing functions, and need additional calling measures if Current Year is exposed separately.

The important lesson is that centralizing calculations doesn't automatically centralize every rule that depends on them. How those calculations reference one another matters just as much.

02
MAINTENANCE TEST

Test 2: Add Rolling 12 Months

Now the business wants another comparison: Rolling 12 Months. This time, we're introducing a new calculation rather than changing an existing one. It needs to become available across all four KPIs.

We'll anchor the rolling window to the latest date in the current filter context, so this comparison remains independent of the completed-month cutoff introduced in Test 1.

APPROACH 01

With Calculation Groups

We add one calculation item to our existing Time Comparison group:

DAX Rolling 12 Months Ā· Calculation Item
CALCULATE(
    SELECTEDMEASURE(),
    DATESINPERIOD(
        'Date'[Date],
        MAX('Date'[Date]),
        -12,
        MONTH
    )
)

Once added, Rolling 12 Months becomes available alongside Current Year, Previous Year, and YoY% in our calculation-group selection. No separate Rolling 12 Months measures are needed for Revenue, Cost, Units Sold, or Margin %.

APPROACH 02

With DAX UDFs

We create a reusable function with the same calculation:

DAX UDF Rolling12Months Ā· DAX UDF
DEFINE
    FUNCTION Rolling12Months =
        (MeasureExpr : MEASUREREF) =>
            CALCULATE(
                MeasureExpr,
                DATESINPERIOD(
                    'Date'[Date],
                    MAX('Date'[Date]),
                    -12,
                    MONTH
                )
            )

The calculation itself is still defined once. But in our explicit-measure implementation, we also need calling measures to expose Rolling 12 Months for each KPI:

DAX Calling Rolling12Months Ā· KPI Measures
Revenue R12M = Rolling12Months([Revenue])
Cost R12M = Rolling12Months([Cost])
Units Sold R12M = Rolling12Months([Units Sold])
Margin % R12M = Rolling12Months([Margin %])

We then add these measures to the report's selection mechanism.

One detail matters for Margin %. The rolling calculation should evaluate the underlying margin measure over the full period, rather than adding or averaging monthly percentages. This works when the base measure calculates Margin % from the relevant aggregated values.

āœ“ TEST 02 Ā· THE FINDING

Calculation groups make this extension straightforward: one new calculation item works across the existing KPIs.

UDFs also centralize the calculation, but our implementation needs one function, four calling measures, and an update to the reporting selection.

Scale that to forty KPIs. The Rolling 12 Months logic is still written once in either approach, but the UDF version would require forty additional calling measures under this design.

That's the difference between reusing a calculation and making it available across an entire reporting model.

03
MAINTENANCE TEST

Test 3: Add Another KPI

Let's reverse the situation. Instead of introducing another comparison, the business adds a fifth KPI: Gross Profit.

DAX Gross Profit Ā· Base Measure
Gross Profit = [Revenue] - [Cost]

Gross Profit needs to support Current Year, Previous Year, YoY%, and Rolling 12 Months.

APPROACH 01

With Calculation Groups

Once we create the base measure, all four existing calculation items can apply to it. We don't need additional time-intelligence DAX. We only need to make Gross Profit available in the relevant report visuals or KPI selection.

APPROACH 02

With DAX UDFs

Our functions are already available, so there's no reason to change them. We create the comparison measures that call those functions:

DAX Gross Profit Ā· Comparison Measures
Gross Profit CY = CurrentYear([Gross Profit])
Gross Profit PY = PreviousYear([Gross Profit])
Gross Profit YoY% = YoYGrowth([Gross Profit])
Gross Profit R12M = Rolling12Months([Gross Profit])

We also expose the new measures through the report's selection mechanism.

āœ“ TEST 03 Ā· THE FINDING

Adding another KPI is manageable in both approaches. The calculation-group version needs only the new base measure and its inclusion in the report selection.

The UDF version reuses the existing functions, but our explicit-measure design requires four additional comparison measures for Gross Profit.

The more KPIs and comparisons we introduce, the more noticeable the difference becomes. Reusable logic doesn't necessarily mean fewer model objects to maintain.

What Changed Across the Three Tests?

Three requests, two implementations. Here's what we actually had to change.

Maintenance test Calculation Groups DAX UDFs
Revise completed-month comparison Update 3 calculation items (CY, PY, YoY%) Add 1 function, update 2 functions + add 4 CY measures
Add Rolling 12 Months Add 1 calculation item Add 1 function + 4 calling measures
Add Gross Profit Add 1 base measure Add 1 base measure + 4 calling measures
Reporting updates Expose new KPI where needed Extend KPI/comparison selection

These counts reflect our chosen implementations, not fixed limitations of either feature. We could structure the functions differently, automate measure creation, or combine both approaches.

But the three tests reveal something worth paying attention to: reusing calculation logic and reducing the number of objects we maintain are two different things.

Calculation groups make it easier to apply the same transformation across many measures. Adding another comparison or KPI doesn't necessarily mean adding more measures.

UDFs give us a different kind of flexibility. We can define reusable calculations, compose functions, and control exactly where that logic is applied. The trade-off in our implementation is the additional measures needed to expose those calculations. And that distinction becomes more important as the model grows from four KPIs to forty.

↗ THE NEXT CHALLENGE
KPI EXCEPTIONS

But so far, we've assumed every KPI follows the same rules. What happens when one of those forty KPIs needs a different calculation from the rest?

When One Rule Doesn't Fit Every Measure

So far, we've assumed every KPI can use the same comparison logic. But that's not always how business reporting works.

Take Margin % from our model. For Revenue and Cost, YoY% tells us how much the value has grown or declined relative to the previous year. For Margin %, however, the business might want to see the change in percentage points instead.

MARGIN CHANGE 30% → 35% Same starting values
RELATIVE GROWTH 16.7% (35% āˆ’ 30%) / 30%
PERCENTAGE-POINT CHANGE +5 pp 35% āˆ’ 30%

Both are mathematically correct, but they tell different stories. Our existing YoY% calculation returns the first. The business expects the second.

How Do We Handle the Exception?

APPROACH 01

With Calculation Groups

We can modify the existing YoY% calculation item to recognize Margin % and apply a different calculation. The completed-month comparison logic from Test 1 stays the same; only the way we calculate the difference changes.

DAX YoY% Ā· Margin % Exception
-- Use the completed-month comparison window
VAR Cutoff = EOMONTH(TODAY(), -1)
VAR PYCutoff = EDATE(Cutoff, -12)
VAR CY =
    CALCULATE(
        SELECTEDMEASURE(),
        DATESBETWEEN(
            'Date'[Date],
            DATE(YEAR(Cutoff), 1, 1),
            Cutoff
        )
    )
VAR PY =
    CALCULATE(
        SELECTEDMEASURE(),
        DATESBETWEEN(
            'Date'[Date],
            DATE(YEAR(PYCutoff), 1, 1),
            PYCutoff
        )
    )
RETURN
    IF(
        ISSELECTEDMEASURE([Margin %]),
        CY - PY,
        DIVIDE(CY - PY, PY)
    )

The exception stays within the calculation group, so our existing report selection continues to work. When Margin % is selected, the YoY% item returns a percentage-point difference. For other KPIs, it returns relative growth.

But we've introduced something new: our shared YoY% calculation now needs to know which measure it's evaluating.

One exception is manageable. With forty KPIs, several exceptions could turn a reusable calculation item into a growing collection of measure-specific conditions.

APPROACH 02

With DAX UDFs

Instead of changing our existing YoYGrowth function, we can introduce a separate function for percentage-point differences.

And because we already created CurrentYear and PreviousYear in Test 1, we don't need to write the completed-month logic again.

DAX UDF PercentagePointChange Ā· DAX UDF
DEFINE
    FUNCTION PercentagePointChange =
        (MeasureExpr : MEASUREREF) =>
            -- Reuse the completed-month period functions
            VAR CY = CurrentYear(MeasureExpr)
            VAR PY = PreviousYear(MeasureExpr)
            RETURN
                CY - PY

Then we create a calling measure specifically for Margin %:

DAX Margin PP Change Ā· Calling Measure
Margin PP Change =
    PercentagePointChange([Margin %])

Our existing YoYGrowth function remains unchanged and can continue supporting Revenue, Cost, and Units Sold. But there's one additional step: the report needs to use Margin PP Change instead of Margin YoY% wherever the business expects percentage-point movement.

If we're using a field parameter, we'd replace the relevant measure reference and update its label. Otherwise, users could end up seeing two different interpretations of Margin % growth without knowing which one they're looking at.

This is where explicit function calls can be useful. We decide which calculation belongs to which KPI, rather than placing every exception inside a shared transformation. Neither approach eliminates the exception. The difference is where we maintain it.

What About Formatting?

There's another practical detail we shouldn't overlook: the calculation might be correct while its presentation is misleading.

Revenue should normally display as currency, Units Sold as a whole number, and Margin % as a percentage. But comparison results introduce another layer of formatting.

For example, when Margin % moves from 30% to 35%, the DAX calculation returns 0.05. That's a +5 percentage-point change, not 5% relative growth.

With calculation groups, we can use a conditional format string expression to handle the Margin % exception. With UDF-based measures, we can apply the appropriate format to the calling measure.

A format such as +0.0 "pp";-0.0 "pp";0.0 "pp" needs the decimal result multiplied by 100 before display, so the stored value 0.05 appears as +5.0 pp. If we want to keep the calculation result as 0.05, we can instead use a percentage-scaled format such as +0.0% "pp";-0.0% "pp";0.0% "pp", which displays +5.0% pp and is less natural. A dedicated display measure or a carefully designed dynamic format is preferable when we need the exact +5.0 pp label.

I'd also make the distinction visible in the report itself. Margin Change (pp) communicates the business meaning much more clearly than another generic YoY% heading.

The bigger question isn't whether either feature can handle exceptions. Both can. It's how much complexity we're willing to introduce into shared logic before a different design becomes easier to maintain.

What Does This Tell Us?

Both approaches handled the Margin % exception without rewriting the underlying time-intelligence logic. But they handled it in different places.

With calculation groups, we introduced measure-specific behavior inside an existing calculation item. The reporting structure stayed intact, but the shared logic became more conditional.

With UDFs, we created a separate function using our existing period calculations. The shared YoY% function stayed unchanged, but we needed another calling measure and a reporting update.

The question isn't simply which approach handles exceptions better. It's where we want that complexity to live. A few exceptions may be easy to manage within a calculation group. As exceptions grow, explicitly defined functions and measures might become easier to follow.

↗ THE NEXT QUESTION
MAINTENANCE EFFORT

We've changed the rules, extended the model, added another KPI, and handled an exception. So what have we actually saved in maintenance effort?

What Did We Actually Save?

We started with four KPIs and three comparisons. Since then, we've changed the reporting period, introduced Rolling 12 Months, added Gross Profit, and handled a Margin % exception.

Here's what those changes required in our two implementations.

What changed Calculation Groups DAX UDFs
Completed-month comparison 3 calculation items modified (CY, PY, YoY%) 1 function added, 2 modified + 4 CY measures added
Rolling 12 Months 1 calculation item added 1 function + 4 calling measures added
Gross Profit KPI 1 base measure added 1 base measure + 4 comparison measures added
Margin % exception Existing YoY% item modified + conditional formatting 1 specialized function + 1 calling measure added
Reporting setup Expose Gross Profit; clarify Margin % label Extend measure selection; replace Margin YoY% where needed

These counts are specific to the implementations we've chosen. They aren't a measure of execution performance, and they don't tell us how long each change would take in a real project. What they do show is where the maintenance effort accumulates.

When we changed the completed-month rule, neither approach was a single-line fix. The calculation group needed changes to three items, while the UDF version needed changes to its reusable functions and additional measures to expose Current Year.

When we added Rolling 12 Months, the difference became clearer. One calculation item made the new comparison available across all existing KPIs. The UDF version reused one function but still needed a calling measure for each KPI.

The Margin % exception revealed another trade-off. Calculation groups preserved the existing selection structure but introduced a measure-specific condition. UDFs kept the exception separate, at the cost of another function and measure.

For me, the most useful distinction is this: reducing duplicated DAX and reducing the number of objects we maintain are two different achievements.

UDFs can help us centralize and compose reusable business logic. Calculation groups can help us apply shared transformations across many measures without creating individual comparison measures for every combination. Neither automatically guarantees a simpler model.

And that's where the forty-KPI scenario becomes interesting. The number of calculations isn't the only thing that grows. So do the exceptions, dependencies, reporting selections, and decisions about where each rule belongs.

Rather than asking which feature replaces the other, I'd look at three things: what needs to be reused, what changes most often, and how many exceptions the model is likely to accumulate.

↗ THE NEXT QUESTION
COMBINING APPROACHES

If calculation groups and UDFs solve different maintenance problems, why would we need to choose only one?


Closing Thoughts

Nothing, really. And that's probably what I find most interesting about this experiment.

Over the years, I've become a lot more careful about introducing reusable logic into a Power BI model. Earlier, I would have considered removing duplicated DAX a clear improvement. These days, I find myself asking a different question: will someone, including me six months later, actually find this easier to understand and change?

That's why I wouldn't rush to replace calculation groups with UDFs, or use calculation groups everywhere simply because they're convenient. I can see a place for both. Calculation groups make sense when I want consistent transformations across many measures, while UDFs give me another way to reuse logic more deliberately.

If there's one thing experience has changed about how I approach DAX, it's that I care less about how clever the implementation looks and more about how easily I can come back and change it.