Forum Discussion

JBI's avatar
JBI
Frequent Visitor
7 years ago
Solved

Rolling Sum for 5 Days Only

Hi Guys,

 

I want to determine the rolling total of sales, taking only the previous 5 days into account. So if today is the 9th of July 2019, only data from the 5th until now. Rest to be zero.

 

Table (Goods sold) with Date and Sales columns. I need the measure to create "Previous 5 Days"

 

DateSalesPrevious 5 Days
2019/07/01100
2019/07/02150
2019/07/03200
2019/07/04300
2019/07/054040
2019/07/061050
2019/07/072070
2019/07/0830100
2019/07/095105

 

Thanks in advance!

  • hi,

     

    you can try this measure:

    Prev 5 days = 
    VAR 
    maxdate = CALCULATE(MAX(Table1[Date]), ALL(Table1))
    VAR
    currentselected = SELECTEDVALUE(Table1[Date])
    VAR
    last5days = maxdate -5
    VAR
    rolling5days = CALCULATE(SUM(Table1[Sales]), FILTER(ALL(Table1[Date]), Table1[Date] > last5days && Table1[Date] <= Currentselected))
    RETURN
    rolling5days

    here is the PBI file

    https://1drv.ms/u/s!Aps8poidQa5zk6pvkzxCUW8XcB24JA

2 Replies