cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
kjel
Frequent Visitor

How to combine several measures into one

I have created several measures to calculate LTM sales, the result works perfectly well but my problem is that I only use the first measure to calculate the second, and the second to calculate the third:

 

Measure 1:

CombinedColumn = CALCULATE(
'Sales'[Sales Amount] + [Remaining Budget]
)

 

Measure 2:

Combined LTM = CALCULATE(
[CombinedColumn],
DATESINPERIOD( 'Date'[DateTime],MAX('Date'[DateTime]),-12,MONTH )
)

Measure 3:

Budget LTM =
VAR LastDateWithSales = CALCULATE( MAX ( Sales[PostingDate]), REMOVEFILTERS())
VAR RB_LTM = CALCULATE(
[Combined LTM],
KEEPFILTERS('Date'[DateTime] >= LastDateWithSales)
)
RETURN
RB_LTM

 

I would really like to combine these three measures into one, this is my attempt at it:

 

Budget LTM =
VAR LastDateWithSales = CALCULATE( MAX ( Sales[PostingDate]), REMOVEFILTERS())
VAR CombinedColumn = CALCULATE(
'Sales'[Sales Amount] + [Remaining Budget]
)
VAR CombinedLTM = CALCULATE(
CombinedColumn,
DATESINPERIOD( 'Date'[DateTime],MAX('Date'[DateTime]),-12,MONTH)
)
VAR BudgetLTM = CALCULATE(
CombinedLTM,
KEEPFILTERS('Date'[DateTime] >= LastDateWithSales)
)
RETURN
BudgetLTM

 

I'm fairly new to DAX, so I assume there is something relatively simple I'm missing.

1 REPLY 1
daXtreme
Solution Sage
Solution Sage

VARiables in DAX are static. They are in fact constants so there's no point doing something like

 

var Variable = ...

return

calculate(

    Variable,

    ...

)

 

This will always return the value of the Variable as it was calculated in the first line...

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors