Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!
I have a metric that calculates cumulative purchases over 30 rolling days:
Cumulative purchases to date =
CALCULATE(
SUM(tab[nb_visits]),
FILTER(
ALLSELECTED(tab),
tab[ref_date] >= MAX(MyCalendar[Date]) - 30
&& tab[ref_date] <= MAX(MyCalendar[Date])
)
)
I want to create a DAX measure called cumulative purchases at m-1 which will calculate the cumulative for the previous month over 30 rolling days
Desired result:
date - cumulative purchases - cumulative purchases at m-1
02/25/2020 - 35 - 18
02/24/2020 - 30 - 16
02/23/2020 - 25 - 14
02/22/2020 - 20 - 12
02/21/2020 - 15 - 10
02/20/2020 - 10 - 8
knowing that the data for the month of December are:
date - cumulative purchases
01/25/2020 - 18
01/24/2020 - 16
01/23/2020 - 14
01/22/2020 - 12
01/21/2020 - 10
01/20/2020 - 8
Solved! Go to Solution.
Hi @forbi ,
According to your description, here are my steps you can follow as a solution.
(1) My test data is the same as yours.
(2) We can create a measure.
cumulative purchases at m-1 =
var _date=MAX('MyCalendar'[Date])-31
RETURN CALCULATE([cumulative purchases],FILTER(ALLSELECTED('tab'),'tab'[date]=_date))
(3) Then the result is as follows.
If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hello,
I would like to share the solution that I found and which meets my needs,
Regards
___________________________________________________
cumulative purchases =
VAR __Date = LASTDATE(date[Date])
VAR __PrvEndDate = __Date
VAR __PrvStartDate =
CALCULATE(
MIN(tab[date]),
FILTER(
ALLSELECTED(tab),
[purshases - M-1] <> BLANK()
)
)
RETURN
CALCULATE(
SUM(tab[purchases]),
FILTER(
ALLSELECTED(tab),
tab[date] >= __PrvStartDate
&& tab[date] <= __PrvEndDate
)
)purshases - M-1 = VAR __Date = MAX(date[Date])
VAR __PrvEndDate = __Date - 30
VAR __PrvStartDate = __Date - 60
RETURN
CALCULATE(
SUM(tab[purshases]),
FILTER(
ALLSELECTED(tab),
tab[date] >= __PrvStartDate
&& tab[date] <= __PrvEndDate
)
)
Hello,
I would like to share the solution that I found and which meets my needs,
Regards
___________________________________________________
cumulative purchases =
VAR __Date = LASTDATE(date[Date])
VAR __PrvEndDate = __Date
VAR __PrvStartDate =
CALCULATE(
MIN(tab[date]),
FILTER(
ALLSELECTED(tab),
[purshases - M-1] <> BLANK()
)
)
RETURN
CALCULATE(
SUM(tab[purchases]),
FILTER(
ALLSELECTED(tab),
tab[date] >= __PrvStartDate
&& tab[date] <= __PrvEndDate
)
)purshases - M-1 = VAR __Date = MAX(date[Date])
VAR __PrvEndDate = __Date - 30
VAR __PrvStartDate = __Date - 60
RETURN
CALCULATE(
SUM(tab[purshases]),
FILTER(
ALLSELECTED(tab),
tab[date] >= __PrvStartDate
&& tab[date] <= __PrvEndDate
)
)
Hi @forbi ,
According to your description, here are my steps you can follow as a solution.
(1) My test data is the same as yours.
(2) We can create a measure.
cumulative purchases at m-1 =
var _date=MAX('MyCalendar'[Date])-31
RETURN CALCULATE([cumulative purchases],FILTER(ALLSELECTED('tab'),'tab'[date]=_date))
(3) Then the result is as follows.
If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
@forbi So like this?
Cumulative purchases previous 30 days =
VAR __Date = MAX(MyCalendar[Date])
VAR __PrvEndDate = __Date - 31
VAR __PrvStartDate = __Date - 61
VAR __Table = FILTER(ALLSELECTED('tab'), [Date] >= __PrvStartDate && [Date] <= __PrvEndDate)
VAR __Result = SUMX( __Table, [nb_visits] )
RETURN
__Result
Thank you but it does not work 😕
when I create a table like this, column cumulative purchases at m-1 remains empty
date - cumulative purchases - cumulative purchases at m-1
02/25/2020 - 35 -
02/24/2020 - 30 -
02/23/2020 - 25 -
02/22/2020 - 20 -
02/21/2020 - 15 -
02/20/2020 - 10 -
I want a result like that :
date - cumulative purchases - cumulative purchases at m-1
02/25/2020 - 35 - 18
02/24/2020 - 30 - 16
02/23/2020 - 25 - 14
02/22/2020 - 20 - 12
02/21/2020 - 15 - 10
02/20/2020 - 10 - 8
Vote for your favorite vizzies from the Power BI World Championship submissions!
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
Check out the January 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 58 | |
| 52 | |
| 40 | |
| 17 | |
| 16 |
| User | Count |
|---|---|
| 112 | |
| 109 | |
| 40 | |
| 33 | |
| 27 |