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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
nicpatridge
Frequent Visitor

Running Average in a Matrix Visualization

I've looked at several rolling average posts, but none of them seem to fit my situation and data. Let's say I have this in a table:

 

ClientWeekEndDateCharges
Client A4/4/2020123
Client B4/4/2020198
Client C4/4/2020164
Client A4/11/2020111
Client B4/11/2020164
Client C4/11/2020192
Client A4/18/2020133
Client B4/18/202094
Client C4/18/2020114
Client A4/25/2020160
Client B4/25/2020133
Client C4/25/2020141
Client A5/2/2020101
Client B5/2/2020124
Client C5/2/2020164
Client A5/9/2020138
Client B5/9/2020169
Client C5/9/2020111

 

What I'm ultimately looking for is a rolling average I can display in a matrix. Desired outcome:

 

 4/11/20204/18/20204/25/20205/2/20205/9/2020
Charges467341434389418
Rolling 14 Charges952808775823807
Rolling 14 Average Daily Chagres6857.755.458.857.6

 

I started here, which feels close:

 

AverageCharges14Days =
calculate(
sum('Table1'[Charges]),
filter (
all ( 'Table1'[WeekEndDate] ),
'Table1'[WeekEndDate] <= max('Table1'[WeekEndDate])
&& 'Table1'[WeekEndDate] > ( max('Table1'[WeekEndDate])-14)
)
)/14

 

That method works if I want to do a 7 day average, since each column header is 7 days. When I make it 14 days, though, it just gives me half the 7 day value. I can tell it's simply not including the previous week's Charges in the sum() function, so I guess the filter(all()) isn't what I need. Can someone help me get to the desired outcome?

1 ACCEPTED SOLUTION
nicpatridge
Frequent Visitor

I have solved it. Looks like instead of filter(all()) I should have been using DATESINPERIOD. Thus:

 

AverageCharges14Days =
calculate(
sum('Table1'[Charges]),
DATESINPERIOD('Table1'[WeekEndDate],LASTDATE('Table1'[WeekEndDate]),14,DAY)
)/14

 

This gave me the output I was looking for. 

View solution in original post

3 REPLIES 3
nicpatridge
Frequent Visitor

I have solved it. Looks like instead of filter(all()) I should have been using DATESINPERIOD. Thus:

 

AverageCharges14Days =
calculate(
sum('Table1'[Charges]),
DATESINPERIOD('Table1'[WeekEndDate],LASTDATE('Table1'[WeekEndDate]),14,DAY)
)/14

 

This gave me the output I was looking for. 

mahoneypat
Microsoft Employee
Microsoft Employee

I think you just need >= instead of > to compare to the -14 date.

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Unfortunately, that didn't do anything. I'm pretty sure it's because PBI is only running the measure on lines within that weekendingdate column value. I don't know how to get it to add the previous week's charges before dividing.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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