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
kent_iglehart
New Member

Help calculating a 7 day running total column

I have a table in PowerBI that has the column "Date" and "Sales". I want to create a measure and display it in a table that computes a rolling 7 day total of the "Sales" column. To be clear, I want to see this over time, I do not want it for a single day, I want to create a table exactly like I am showing below, thanks!

 

DateSalesRunning 7 Day Total
1/1/202072 
1/2/20205 
1/3/202034 
1/4/202045 
1/5/202081 
1/6/202060 
1/7/202063360
1/8/20206294
1/9/202053342
1/10/202030338
1/11/202032325
1/12/202035279
1/13/202082301
1/14/202055293
1/15/202099386
1/16/202097430
1/17/2020100500
1/18/202054522
1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

Assuming there is a sale recorded for everyday, try this:

  1. Create a Calendar Table
  2. Build a relationship from the Date column of the Data Table to the Date column of the Calendar Table
  3. To your visual, drag the Date field from the Calendar Table
  4. Write these measures

Total sales = SUM(Data[Sales])

7 days rolling sales = CALCULATE([Totalsales],DATESBETWEEN(Calendar[Date],MIN(Calendar[Date])-6,MIN(Calendar[Date])))

Hope this helps.


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

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

Assuming there is a sale recorded for everyday, try this:

  1. Create a Calendar Table
  2. Build a relationship from the Date column of the Data Table to the Date column of the Calendar Table
  3. To your visual, drag the Date field from the Calendar Table
  4. Write these measures

Total sales = SUM(Data[Sales])

7 days rolling sales = CALCULATE([Totalsales],DATESBETWEEN(Calendar[Date],MIN(Calendar[Date])-6,MIN(Calendar[Date])))

Hope this helps.


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

@Ashish_Mathur  thank you so much that worked amazing and did exactly what I wanted. I can't tell you much I appreciate your help : )!

You are welcome.


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

In case you use date calendar

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

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

Greg_Deckler
Super User
Super User

I can't think of a time intelligence measure for that. See if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.