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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

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, @Anonymous 

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, @Anonymous 

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.
Anonymous
Not applicable

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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