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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Running Total for above n rows

Hi everyone, 

I have a table of daily sales, and Need to calculate the running total of current day + previous 4 days ..

Example below: 

 

mazer_0-1638786784888.png

 

Any help or advice please ?

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Create a measure like, Prefer date tbale

 

Rolling 4 = CALCULATE(Sum(Sales[Sales]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-4,DAY))

 

or

Rolling 4 = CALCULATE(Sum(Sales[Sales]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-5,DAY))

View solution in original post

4 REPLIES 4
MFelix
Super User
Super User

Hi @Anonymous ,

 

You need to create a measure that picks up the last date try something similar to:

 

Running 4 days =
CALCULATE (
    SUM ( TAble[Sales] ),
    FILTER (
        ALL ( Table[Date] ),
        Table[Date] <= MAX ( Table[Date] )
            && Table[Date]
                >= MAX ( Table[Date] ) - 4
    )
)

Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



jeroendekk
Resolver IV
Resolver IV

Hi @Anonymous 
First you will probably need a datetable in your model. After that you can achieve this with the DATESINPERIOD function in a measure like this.

Current and Previous 4 days = 

CALCULATE(
     SUM('Table'[Sales]), 
     DATESINPERIOD(Datetable[Date], MAX(Datetable[Date]), -5, DAY))

aaaimage.jpg

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

Best regards,
Jeroen

amitchandak
Super User
Super User

@Anonymous , Create a measure like, Prefer date tbale

 

Rolling 4 = CALCULATE(Sum(Sales[Sales]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-4,DAY))

 

or

Rolling 4 = CALCULATE(Sum(Sales[Sales]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-5,DAY))

How to do calculation for above solution if dates are having alternate 7 days date.

ex.

01-08-2023

08-08-2023

15-08-2023

like this.

 

please porvide solution, I tried using this bt data is not given properly

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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