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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
wplante
New Member

Calculating a dynamic average of a measure that is between a date range

Hi,

I would like to create a measure that is the rolling average of the values from another measure (a percent). I would like the measure to add up those percentages that are between the current record date and those that are within the last six days and average the result. I'm fairly new to Dax, but have spent several hours trying to figure out the synatax when dealing with an average of a measure and not a column. However, every way I try this I run into problems with the % Coverage column being a measure and not a column. I wonder if anyone can point me in the right direction? I have tried something like this and it didn't give me the correct  results.

Average Sales 1 = AVERAGEX('qry_InternalFigures','qry_InternalFigures'[Coverage Sales%](filter('qry_InternalFigures','qry_InternalFigures'[Date Given].[Date]<='qry_InternalFigures'[Date Given] && 'qry_InternalFigures'[Date Given].[Date] >= DATEADD('qry_Calendar'[Date],-6,DAY))))
1 ACCEPTED SOLUTION
Anonymous
Not applicable

[Average Sales 1] =
var PeriodToAverageOver =
	DATESINPERIOD(
		// I just hope this table is a 
		// properly built date table.
		// IF not, please read dax.guide/datesinperiod
		// and build a table they talk about
		// in there.
		'qry_Calendar'[Date],
		MAX( 'qry_Calendar'[Date] ),
		-6,
		DAY
	)
var Result =
	AVERAGEX(
		PeriodToAverageOver,
		// I hope the below is a
		// measure. It can't be
		// a column in a table.
	    [Coverage Sales%]
	)
return
	Result
	
// Now, go to https://www.sqlbi.com/articles/rules-for-dax-code-formatting/
// and follow the rules RELIGIOUSLY. You'll
// thank me later 🙂

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

[Average Sales 1] =
var PeriodToAverageOver =
	DATESINPERIOD(
		// I just hope this table is a 
		// properly built date table.
		// IF not, please read dax.guide/datesinperiod
		// and build a table they talk about
		// in there.
		'qry_Calendar'[Date],
		MAX( 'qry_Calendar'[Date] ),
		-6,
		DAY
	)
var Result =
	AVERAGEX(
		PeriodToAverageOver,
		// I hope the below is a
		// measure. It can't be
		// a column in a table.
	    [Coverage Sales%]
	)
return
	Result
	
// Now, go to https://www.sqlbi.com/articles/rules-for-dax-code-formatting/
// and follow the rules RELIGIOUSLY. You'll
// thank me later 🙂

I just wanted to thank you for that solution. I really have been struggling all day on it and I appreciate that you would take the time to answer....and yes, I'm will investigate the proper format for following dax code formatting "religiously" going forward.

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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