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

Moving Average n existing days

Hi,

I have been using power bi for a short time, I think it is an incredible tool although somewhat tedious for people who started with it.

I tell you my problem, I want to calculate a moving average of the last 7 existing days, for example in my table I have no sales from day 2 to day 9 and when using DATESINPERIOD it makes the moving average only with days 10 and 9. I would like calculate the moving average with the n existing days in the table.

 

Gpierot_0-1629717980821.png


Greetings and thanks for your time.



1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , are you using date table and date in visual is coming from date table ?

 

example

Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-7,Day))

 

use date from date table

 

if you only want work with avaiable dates

 

create a rank in table

rank date = rankx(Table, Table[Date],,asc,dense)

 

Then create a measure

calculate(sum(table[sales]), filter(allselected(Table), Table[rank date] >= max(Table[rank date]) -7 &&

Table[rank date] <= max(Table[rank date]) ))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @amitchandak ,

No, i dont have one, the date in visual is coming from sales table.

 

@Anonymous , check if one of the two solution I suggested can help you.

 

One with date table.

 

One without it

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
amitchandak
Super User
Super User

@Anonymous , are you using date table and date in visual is coming from date table ?

 

example

Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-7,Day))

 

use date from date table

 

if you only want work with avaiable dates

 

create a rank in table

rank date = rankx(Table, Table[Date],,asc,dense)

 

Then create a measure

calculate(sum(table[sales]), filter(allselected(Table), Table[rank date] >= max(Table[rank date]) -7 &&

Table[rank date] <= max(Table[rank date]) ))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Thank you very much for the help, it worked perfectly!!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

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

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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.