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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
mlapu
Frequent Visitor

Rolling Average that works with a custom date hierarchy

Hi, 

I am building a visual that shows the amount of time my piece of equipment runs each week (in hours). Each row of the data is 15 minutes, so there are 4 rows per hour.

 

If the equipment is running for that interval, the value is 1, if it is shut down, the value is zero.

mlapu_0-1628004125841.png

 

I have the graph built using a custom date hierarchy:

mlapu_1-1628004243962.pngmlapu_2-1628004301782.png

 

Now I would like to add a rolling average to the graph. I can't use the Rolling Average Quick Measure because the the hierarchy isn't recognized as a date hierarchy (with the little calendar icon).  Anyone have thoughts on how I can implement a rolling average to this data? 

 

1 ACCEPTED SOLUTION
v-kkf-msft
Community Support
Community Support

Hi @mlapu ,

 

I made some changes to the quick measure formula so that it calculates the weekly average rolled back to the past two months.

 

rolling average = 
VAR __LAST_DATE = ENDOFMONTH('Date'[Date])
VAR __DATE_PERIOD =
	DATESBETWEEN(
		'Date'[Date],
		STARTOFMONTH(DATEADD(__LAST_DATE, -2, MONTH)),
		__LAST_DATE
	)
RETURN
	AVERAGEX(
		CALCULATETABLE(
			SUMMARIZE(
				VALUES('Date'),
				'Date'[Year],
				'Date'[Month Name],
				'Date'[Week of Month]
			),
			__DATE_PERIOD
		),
		CALCULATE(
			SUM('Table'[A041DC01SCRBR_STARTUP_CMPL_VAL0]),
			ALL('Date'[Date])
		)
	)

image.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

3 REPLIES 3
v-kkf-msft
Community Support
Community Support

Hi @mlapu ,

 

I made some changes to the quick measure formula so that it calculates the weekly average rolled back to the past two months.

 

rolling average = 
VAR __LAST_DATE = ENDOFMONTH('Date'[Date])
VAR __DATE_PERIOD =
	DATESBETWEEN(
		'Date'[Date],
		STARTOFMONTH(DATEADD(__LAST_DATE, -2, MONTH)),
		__LAST_DATE
	)
RETURN
	AVERAGEX(
		CALCULATETABLE(
			SUMMARIZE(
				VALUES('Date'),
				'Date'[Year],
				'Date'[Month Name],
				'Date'[Week of Month]
			),
			__DATE_PERIOD
		),
		CALCULATE(
			SUM('Table'[A041DC01SCRBR_STARTUP_CMPL_VAL0]),
			ALL('Date'[Date])
		)
	)

image.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Hi Winniz,

Thank you for your time and effort! Unfortunately there is an error:

mlapu_0-1628165335678.png

I have gotten this error a lot while working with this data, and has forced me to make some creative adjustments to my code at times. Here is a snap shot of the Date column:

mlapu_1-1628165505910.png

Any thoughts on how I can bypass this error?

 

Thanks again for the help!

Mark

Hi @mlapu ,

 

When referencing the date column in the DATESBETWEEN function, the same date cannot have different timestamps. So you cannot use the timestamp column in the DATESBETWEEN function, you need to create a new date column in the table.

 

Date = 'Table'[timestamp].[Date]

Or

Date = DATE(YEAR('Table'[timestamp]), MONTH('Table'[timestamp]), DAY('Table'[timestamp]))

image.png

 

And if you have associated Date table, you need to modify the relationship between the tables to: the Date column in Date -- the Date column in Table.

 

vkkfmsft_0-1628227567428.png

 

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors