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
Limerick
Frequent Visitor

SUM dynamic / dependend on date

Hello together, 

 

I have a table like this:

Limerick_0-1684509537713.png

What I need to do now, is to sum the amount for every row over the past 5 days, like this:

Limerick_3-1684509846404.png

So basically, sum everything up, where the date is 5 days younger, then the current date.

The result hast to be in a column, not a measure.
Can you please help me out? Thank you a lot in advance! 🙂 

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

Create an Index column in the Query Editor and write this calculated column formula

Column = CALCULATE(SUM(Data[Amount]),FILTER(Data,Data[Date]>=EARLIER(Data[Date])-4&&Data[Date]<=EARLIER(Data[Date])&&Data[Index]<=EARLIER(Data[Index])))

Hope this helps.

Untitled.jpg


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

Create an Index column in the Query Editor and write this calculated column formula

Column = CALCULATE(SUM(Data[Amount]),FILTER(Data,Data[Date]>=EARLIER(Data[Date])-4&&Data[Date]<=EARLIER(Data[Date])&&Data[Index]<=EARLIER(Data[Index])))

Hope this helps.

Untitled.jpg


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
lbendlin
Super User
Super User

Power BI aggregates by default. You will need to add an index column to your data.

 

your expected outcome does not match the sample data (Feb 5 is missing)

 

Does "last five days" include or exclude the current date?

test = DATATABLE("Index",INTEGER,"Date",DATETIME,"Amount",CURRENCY,{
    {1,dt"2023-02-01",100},
    {2,dt"2023-02-01",100},
    {3,dt"2023-02-02",120},
    {4,dt"2023-02-02",150},
    {5,dt"2023-02-04",120},
    {6,dt"2023-02-05",100},
    {7,dt"2023-02-07",200},
    {8,dt"2023-02-08",250}
    }
    )

Last five days = 
var i=[Index]
var d=[Date]
return CALCULATE(sum([Amount]),all(test),test[Index]<=i,test[Date]<=d,test[Date]>=d-5)

 

lbendlin_0-1684719904917.png

 

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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.