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
Anonymous
Not applicable

How to get the the sum of previous month values in DAX

Hi All,

Can you please help me to achieve a logic to calculate the Final Value(column) logic by using DAX .

My case is to have "0' for January 2022 and for Feb the value should be Jan 2022 and For April the value should be sum(Jan,feb,Mar) and for May it should be sum(Jan,Feb,mar,Apr).

I am creating a measure , For which  I have created "start range" and "End Range" measures to get this Final Value column to be created. Please help

MonthStart RangeEndRangeAttritionFinal Value
1/1/221/1/221/31/22100
2/1/221/1/221/31/222010
3/1/221/1/222/28/223030
4/1/221/1/223/31/224060
5/1/221/1/224/30/2250100
6/1/221/1/225/31/2260150
7/1/221/1/226/30/2270200

 

Thanks in advance,

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hello, 
You can use the following measure to calculate rolling sum for previous months. 

Find Value =
IF(SELECTEDVALUE('Table'[Month]) = 1, 0,
CALCULATE(
SUM('Table'[Attrition]),
FILTER(
ALLSELECTED('Table'[Date]),
'Table'[Date]< MAX('Table'[Date]))
))

Output:
Month = Month(Table[Date])
Pragati_Sharma_0-1659699378226.png

 

 

View solution in original post

7 REPLIES 7
OliT
Resolver I
Resolver I

Hi @Anonymous 

Please try this measure

 

measure =
SUMX (
    FILTER ( ALL ( 'table' ), 'table'[MonthStart] < MAX ( 'table'[MonthStart] ) ),
    [Attrition]
)

 

 

Regards,

OliT

Anonymous
Not applicable

Hello, 
You can use the following measure to calculate rolling sum for previous months. 

Find Value =
IF(SELECTEDVALUE('Table'[Month]) = 1, 0,
CALCULATE(
SUM('Table'[Attrition]),
FILTER(
ALLSELECTED('Table'[Date]),
'Table'[Date]< MAX('Table'[Date]))
))

Output:
Month = Month(Table[Date])
Pragati_Sharma_0-1659699378226.png

 

 
Anonymous
Not applicable

Hi @Anonymous 

Thanks for the quick reply,

Unfortunately I cannot use "Attrition" in the SUM because  it was derived using the below logic measures. Please help me how to crack this.

 

Attrition = CALCULATE (
DISTINCTCOUNT( employee[employee_code] ),
  employee[Attrition filter] = "yes"
)
 
Attrition filter =
var monthkey = year([Month])&FORMAT(month([Month]),"00")
var lwdmmyy= year([LWD])&FORMAT(month([LWD]),"00")
return
IF( lwdmmyy=monthkey, "yes","No")
 
Thanks,
Anonymous
Not applicable

@ddpl - Hi, Looking for your reply/ any alternate solution. Thank you in advance

ddpl
Solution Sage
Solution Sage

@Anonymous ,Hey bro

 

You don't need other column to get running total like Start or End Range

Just create a measure as below and put it along with Date and Attrition in Table...

 

Your Need = 

VAR need = CALCULATE(SUM('Table'[Attrition]), FILTER(ALLSELECTED('Table'), 'Table'[Date]<MAX('Table'[Date])))

RETURN IF(need=BLANK(), 0, need)
Anonymous
Not applicable

Hi @ddpl ,

Thanks for the quick reply,

Unfortunately I cannot use "Attrition" in the SUM because  it was derived using the below logic measures. Please help me how to crack this.

 

Attrition = CALCULATE (
DISTINCTCOUNT( employee[employee_code] ),
  employee[Attrition filter] = "yes"
)
 
Attrition filter =
var monthkey = year([Month])&FORMAT(month([Month]),"00")
var lwdmmyy= year([LWD])&FORMAT(month([LWD]),"00")
return
IF( lwdmmyy=monthkey, "yes","No")
 
Also, what is  need in the below line of your code:
RETURN IF(need=BLANK(), 0, need)
Thanks
 
amitchandak
Super User
Super User

@Anonymous , You can join date with date table and can use time intelligence

 

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))


last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last month Sales = CALCULATE(SUM(Sales[Sales Amount]),previousmonth('Date'[Date]))

 

Power BI — Month on Month with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-mtd-questions-time-intelligence-3-5-64b0b4a4090e
https://www.youtube.com/watch?v=6LUBbvcxtKA

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Top Solution Authors