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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
lmagazzi
New Member

Cumulative sum until a date and Sum for last days

Hi everybody,
I'm new to Power BI and there are a few of DAX's issues which are not so easy to understand; although I read some old posts I was not able to find an answer to my question.
This is my problem:
I've got a table like the one below 

Date(YYMMDD)ProductTypeDailySales
211101A11
211101B10
211101C21
211102A8
211102B22
211102C1
211103A14
211103B2
211103C13
211104A2
211105A4
211106A3
211107A8
211108A20


and so on for thousands of rows; for every pair of Data+Product Type I would like to have in the same table or in a new one something like the following:

Date(YYMMDD)ProductTypeDailySalesCumulatedSalesSalesInLast7Days
211101A111111
211101B101010
211101C212121
211102A81919
211102B223233
211102C12222
211103A143333
211103B23434
211103C133535
211104A23535
211105A43939
211106A34242
211107A85050
211108A207059

and so on...
-CumulatedSales is the sum the sales of the product type in the current row from first day until the current day , for every row)
- SalesInLast7Days is the sum of the sales of the product type in the current row in last 7 days (sales of current date of that product type plus sales of previous day and so on untile the previous 6th day, as you can see  it differs from the CumulatedSales column after the first week).
I dont't know if these new columns would be Calculated Columns, or Measures, or they must be in an another table ...In Excel it's rather simple with SumIfS but in DAX it seems I need to make a filter for every rows ... but how can I filter sales data in other rows in DAX?
Could someone please kindly help me to solve this issue?

1 ACCEPTED SOLUTION
ValtteriN
Super User
Super User

Hi,

I recommend creating measures. For RT the baisc pattern is like this:
var maxdate = MAX('CALENDAR'[Date]) return
CALCULATE(SUM(Table[Value]),ALL(CALENDAR),'CALENDAR'[Date]<=maxdate)

Also check this post by SQLBI explaining the logic behind the DAX: https://www.sqlbi.com/articles/computing-running-totals-in-dax/

For last 7 you can just modify the previous dax a bit:

var maxdate = MAX('CALENDAR'[Date]) return
CALCULATE(SUM(Table[Value]),ALL(CALENDAR),'CALENDAR'[Date]<=maxdate,'CALENDAR'[Date]>maxdate-8)


I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/





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

Proud to be a Super User!




View solution in original post

2 REPLIES 2
ValtteriN
Super User
Super User

Hi,

I recommend creating measures. For RT the baisc pattern is like this:
var maxdate = MAX('CALENDAR'[Date]) return
CALCULATE(SUM(Table[Value]),ALL(CALENDAR),'CALENDAR'[Date]<=maxdate)

Also check this post by SQLBI explaining the logic behind the DAX: https://www.sqlbi.com/articles/computing-running-totals-in-dax/

For last 7 you can just modify the previous dax a bit:

var maxdate = MAX('CALENDAR'[Date]) return
CALCULATE(SUM(Table[Value]),ALL(CALENDAR),'CALENDAR'[Date]<=maxdate,'CALENDAR'[Date]>maxdate-8)


I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/





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

Proud to be a Super User!




It works! Thank you very much, i tried something similar but i used the FILTER instruction, not the ALL and the other conditions without Filter . I have to study 🙂 
Thanks a lot

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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