Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
hvanstalle
Frequent Visitor

Rolling average with variable measure

Hello,

 

I created a Rolling average on our efficiency measurement and it works fine:

 

CALCULATE(IF([Efficiency (%)]<>BLANK(),
AVERAGEX(
DATESBETWEEN(
Datetable_months[Datum],
DATEADD(varDate, -12, MONTH),
DATEADD(varDate, 0, MONTH)
),
CALCULATE([Efficiency (%)])
)
)

 

But as I wanted to make this more flexible and also easy to switch between some other KPI measures I created the possibility to choose between the KPI they want. But now my rolling average isn't working anymore. Any idea why? It gives me the correct item, but without the average.

 

12MRol =
VAR varDate = LASTDATE(Datetable_months[Datum])
VAR varItem =
SWITCH(
SELECTEDVALUE(Selection[Item]),
"Efficiency (%)", [Efficiency (%)],
"Home load rate (%)", [Home load rate (%)],
"Load factor (%)",[Load factor (%)],
"Use factor (%)",[Use factor (%)],
"Time use factor (%)", [Time use factor (%)])

Return

CALCULATE(IF(varItem<>BLANK(),
AVERAGEX(
DATESBETWEEN(
Datetable_months[Datum],
DATEADD(varDate, -12, MONTH),
DATEADD(varDate, 0, MONTH)
),
CALCULATE(varItem)
)
))
 
Thanks in advance!
2 REPLIES 2
daxer-almighty
Solution Sage
Solution Sage

Please try to understand how variables in DAX work. Since DAX is a functional language, variables are really... CONSTANT. Once you've grabbed their values, they will never change throughout the execution of the code. So, doing calculate(varItem) = varitem. Always. There is no change here. By the way, a measure is always implicitly wrapped in CALCULATE, so doing this CALCULATE( [Measure] ) is the same as just calling the measure itself.

Ok, thanks for your feedback.

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

Check out the April 2025 Power BI update to learn about new features.

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

Find out what's new and trending in the Fabric community.

Top Kudoed Authors