Power BI December 18, 2021 · 4 min read

Extending calculation groups in Power BI with unstructured data (targets, budgets etc.)

Use SELECTEDMEASURENAME() inside a calculation group to dynamically pull the right target or budget value for whichever measure is active.

Gregor Brunner Gregor Brunner
Extending calculation groups in Power BI with unstructured data (targets, budgets etc.)

Calculation groups in Power BI frequently depend on time intelligence calculations. If you are unfamiliar with this feature, consult the foundational resource on creating calculation groups in Power BI Desktop.

The Challenge

Consider a scenario where you have a fully dynamic calculation group based on time/dates, but need to incorporate unstructured targets or budgets. Additionally, this calculation group must function across multiple measures with their corresponding target values.

Example Scenario

Imagine sales data organized by region with associated DAX measures and time intelligence calculation groups.

The Core Question: What happens when you have multiple measures — such as sales, profit, COGS, quantity sold, or average shipping time — and your calculation group should work consistently across all of them?

The Data Problem

You receive an unstructured Excel spreadsheet containing target and budget values without regional granularity. Instead, you only have overall targets (for example, Year-to-Date figures).

Desired Outcome: When using your sales measure, the calculation group automatically retrieves the corresponding sales target value from your table. When switching to profit measures, it pulls the appropriate profit targets — and so on.

The Solution

Step 1: Add a Calculation Item

Add a new calculation item to your calculation group via Tabular Editor. Name it “Target_YTD” and use this DAX expression:

CALCULATE (
    SUM ( Excel_table[Value] ),
    KEEPFILTERS ( Excel_table[Measure_name] = SELECTEDMEASURENAME() 
    )
)

The SELECTEDMEASURENAME() function is instrumental here. It filters values based on whichever measure you are currently using, retrieving the corresponding target value from your Excel table.

Step 2: Eliminate Duplicate Values

Extend your DAX expression to remove unwanted duplicates:

VAR mycalc = CALCULATE (
    SUM ( Excel_table[Value] ),
    KEEPFILTERS ( Excel_table[Measure_name] = SELECTEDMEASURENAME() 
    )
)

VAR Result = IF( ISINSCOPE(Region[Region]), BLANK(), mycalc )
RETURN Result

This enhanced version uses variables for improved readability and employs the ISINSCOPE() function, which determines whether a specific column exists in the current context.

Key Takeaway

Whatever measure you introduce into your matrix will automatically provide the correct target value, provided the measure name matches the corresponding entry in your Excel sheet. This approach extends beyond targets and budgets to numerous other unstructured data integration scenarios.