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
Dunner2020
Post Prodigy
Post Prodigy

Cumulative sum by the end of last month

Hi there,

 

I am calculating the cumulative sum by the end of last month. I only consider those months that are gone (not the current month). I have developed the measure which looks like as follow:

 

Cumulative sum =

Var last_month_date = EOMONTH(EOMONTH(TODAY(),0),-1)
var CurrentDate = MAX('Table'[Actual Incident Start Time ])
Return
sumx(
filter(ALL('Outages and Interruptions'),'Outages and Interruptions'[Actual Interruption Start Time (NZST)]<=CurrentDate && CurrentDate<=last_month_date ), [sum_measure])
 
However, I noticed that it only calculates the value by the end of August instead of calculating by the end of September. Could anyone guide me where I made the mistake?
5 REPLIES 5
v-stephen-msft
Community Support
Community Support

Hi @Dunner2020 ,

 

It may be because your EOMONTH function is wrong. Try

 

Var last_month_date = EOMONTH(EOMONTH(TODAY(),0),0)

 

Reference: EOMONTH DAX

 

If I fail to answer the question, please provide some sample data, which will be very useful for me to help you.

 

Best Regards,

Stephen Tao

 

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

@v-stephen-msft , your modified statement produces the end date of current month not the last month.

amitchandak
Super User
Super User

@Dunner2020 , Try like

Var last_month_date = EOMONTH(TODAY(),-1)
var CurrentDate = MAX('Table'[Actual Incident Start Time ])
Return
sumx(
filter(ALL('Outages and Interruptions'),'Outages and Interruptions'[Actual Interruption Start Time (NZST)]<=CurrentDate && 'Outages and Interruptions'[Actual Interruption Start Time (NZST)<=last_month_date ), [sum_measure])

 

Please provide your feedback comments and advice for new videos
Tutorial Series Dax Vs SQL Direct Query PBI Tips
Appreciate your Kudos.

@amitchandak , my measure is as follow :

 

var CurrentDate = MAX('Outages and Interruptions'[Actual Interruption Start Time (NZST)])
Var last_month_date = EOMONTH(EOMONTH(TODAY(),0),-1)
Return
sumx(
filter(ALL('Outages and Interruptions'),'Outages and Interruptions'[Actual Interruption Start Time (NZST)]<=CurrentDate && 'Outages and Interruptions'[Actual Interruption Start Time (NZST)]<=last_month_date ),
[sum_measure])
 
it produces the following output:
 Screenshot 2020-10-24 111458.jpg
 

As you can see that it still showing value of September and October.

 
 

 

sevenhills
Super User
Super User

 

a) var last_month_date = EOMONTH(TODAY(), -1)
-- gives last month date. (9/30/2020)
-- Minor, FYI, nothing is wrong in your code ... more of FYI

b) Cumulative Sum calc - Try this
Cumulative sum =
  var last_month_date = EOMONTH(TODAY(),-1)
  Return Calculate (
              SUM( [sum_measure])
         , filter(
             ALL('Outages and Interruptions'[Actual Interruption Start Time (NZST)])
             ,'Outages and Interruptions'[Actual Interruption Start Time (NZST)]
              <= last_month_date ))

 

 

My reason for changing the formula: suspecting ALL('Outages and Interruptions') is wrong
and also, A <= B and B <= C is equal to A <= C

 

         

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.