Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
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.
Greetings and thanks for your time.
Solved! Go to Solution.
@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]) ))
Hi @amitchandak ,
No, i dont have one, the date in visual is coming from sales table.
@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]) ))
Thank you very much for the help, it worked perfectly!!
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
Check out the November 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 59 | |
| 43 | |
| 42 | |
| 23 | |
| 17 |
| User | Count |
|---|---|
| 190 | |
| 122 | |
| 96 | |
| 66 | |
| 47 |