cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dd-edwin
Frequent Visitor

Creating a Rolling Average measure related to another measure (running total)

Hello,

 

Newbie here.

I am running into a problem with trying to create a measure that is related to another measure.

My goal is to create a line chart with the X axis being the week number and Y axis being the averaged running total (+/- 14 days).

 

  • I have a measure to calculate a running total per day
    net_quantity_running_total in Date = 
    CALCULATE(
    	SUM('Table A'[net_quantity]),
    	FILTER(
    		ALL('Date'),
    		ISONORAFTER('Date'[Date], MAX('Date'[Date]), DESC)
    	)
    )
  • I have another measure to calculate the average of the running total over a period of 14 days
    net_quantity_running_total_rolling_average in Date = 
    IF(
    	ISFILTERED('Date'[Date]),
    	ERROR("Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column."),
    	VAR __LAST_DATE = LASTDATE('Date'[Date].[Date])
    	RETURN
    		AVERAGEX(
    			DATESBETWEEN(
    				'Date'[Date].[Date],
    				DATEADD(__LAST_DATE, -14, DAY),
    				DATEADD(__LAST_DATE, 14, DAY)
    			),
    			CALCULATE([net_quantity_running_total in Date])
    		)
    )
  • Table.JPG
  • On a monthly basis, the rolling average values show correctlyTable2.JPG
  • When I drill down to weekly, the X axis does not split into 1-53 weeks. Not sure why it is only showing Week 1, 52, and 53. I'm thinking it could be my rolling average formula due to the LASTDATE variable. I'm not sure how to handle it to show weekly.
    Table4.JPG

I assume it is because the WeekNumber is not actually part of the Date Hierarchy. Is there a way to add the week number to the date hierarchy?

 

Axis.JPG

Thanks,

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

hi, @dd-edwin 

Just adjust the formula as below:

net_quantity_running_total_rolling_average in Date = 
IF(
	ISFILTERED('Date'[Date]),
	ERROR("Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column."),
	VAR __LAST_DATE = LASTDATE('Date'[Date])
	RETURN
		AVERAGEX(
			DATESBETWEEN(
				'Date'[Date],
				DATEADD(__LAST_DATE, -14, DAY),
				DATEADD(__LAST_DATE, 14, DAY)
			),
			CALCULATE([net_quantity_running_total in Date])
		)
)

 

Regards,

Lin

Community Support Team _ Lin
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

2 REPLIES 2
v-lili6-msft
Community Support
Community Support

hi, @dd-edwin 

Just adjust the formula as below:

net_quantity_running_total_rolling_average in Date = 
IF(
	ISFILTERED('Date'[Date]),
	ERROR("Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column."),
	VAR __LAST_DATE = LASTDATE('Date'[Date])
	RETURN
		AVERAGEX(
			DATESBETWEEN(
				'Date'[Date],
				DATEADD(__LAST_DATE, -14, DAY),
				DATEADD(__LAST_DATE, 14, DAY)
			),
			CALCULATE([net_quantity_running_total in Date])
		)
)

 

Regards,

Lin

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

Thank you Lin! That was it! Smiley Very Happy

What is the difference when you reference the date each way?

 

'Date'[Date].Date

'Date'[Date]

 

Wouldn't these give you the same thing?

 

Thanks,

Helpful resources

Announcements
June 2022 update 768X460.jpg

Check it out!

Click here to read more about the June 2022 updates!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors
Top Kudoed Authors