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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
user8289
New Member

How to create a running total column from a certain date range in DAX

I am trying to create a running total of a list of data.  I have data from a large date range but only want to create the running total over the last 7 days and next 7 days

input:

date                size

1-1-2001        20   

2-1-2001        30

3-1-2001        5

3-1-2001        45

4-1-2001        2

5-1-2001        13

6-1-2001        57

output: (For a date range)

date               size           running total

3-1-2001       5                   5

4-1-2001       45                 50

5-1-2001       13                 63

 

I can get the running total measure to work but dont understand how to make it start at a certain date or a number days ago.

this is what I have done so far:

 

test =
CALCULATE(
  SUM('table'[size]),
  FILTER(ALL('table'[Date]), 'table'[Date] <= max('table'[date])
))
 
Any help would be greatly appreciated. 🙂

 

1 ACCEPTED SOLUTION

Hi, @user8289 

 

Replace the formula with the following:

Running total = 
Var _Sum=CALCULATE( SUM('table'[size]),
  FILTER(ALL('table'), 'table'[Date] <= SELECTEDVALUE('table'[date])
 &&[Date]>=MIN('Date'[Date])&&[Date]<=MAX('Date'[Date]
)))
Return
IF(SELECTEDVALUE('Table'[Date])>=MIN('Date'[Date])&&SELECTEDVALUE('Table'[Date])<=MAX('Date'[Date]),_Sum,BLANK())

vzhangti_0-1700551400590.png

Is this the result you expect? Please see the attached document.

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
v-zhangti
Community Support
Community Support

Hi, @user8289 

 

You can try the following methods.
Create a new date table.

vzhangti_0-1700465745534.png

Measure:

Running total = 
Var _Sum=CALCULATE( SUM('table'[size]),
  FILTER(ALL('table'[Date]), 'table'[Date] <= max('table'[date])
                    &&[Date]>=MIN('Date'[Date])&&[Date]<=MAX('Date'[Date]
)))
Return
IF(SELECTEDVALUE('Table'[Date])>=MIN('Date'[Date])&&SELECTEDVALUE('Table'[Date])<=MAX('Date'[Date]),_Sum,BLANK())

vzhangti_1-1700465813267.png

vzhangti_2-1700465831750.png

Is this the result you expect? Please see the attached document.

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks for your reply and sample data. However this did not work for me. Your example seeems to have the required functionality however when applied to my data it gives the result below:

 

user8289_0-1700537695987.png

 

Hi, @user8289 

 

Replace the formula with the following:

Running total = 
Var _Sum=CALCULATE( SUM('table'[size]),
  FILTER(ALL('table'), 'table'[Date] <= SELECTEDVALUE('table'[date])
 &&[Date]>=MIN('Date'[Date])&&[Date]<=MAX('Date'[Date]
)))
Return
IF(SELECTEDVALUE('Table'[Date])>=MIN('Date'[Date])&&SELECTEDVALUE('Table'[Date])<=MAX('Date'[Date]),_Sum,BLANK())

vzhangti_0-1700551400590.png

Is this the result you expect? Please see the attached document.

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

You are awsome!! Thank you thats exactly what I wanted.....

lbendlin
Super User
Super User

1. If you create a calculated column the data will be static (won't change on filtering).  Make sure that is what you want

2.  Read about the WINDOW function and its siblings.

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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