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

View all the Fabric Data Days sessions on demand. View schedule

Reply
Anonymous
Not applicable

How to calculate total sales between start and end of previous month in DAX?

I want to calculate the total sales between start of previous month (example - 1/2/2021) and end of previous month (example - 28/2/2021). Here is my attempt below:

 

 

Month Saving = IF(
    COUNTROWS(Savings)>0,
    CALCULATE(
            SUMX(Savings,Savings[Forecast Annual Cost Reduction - Use USD exchange rate of the day]),
            DATESBETWEEN('Dates'[Date],STARTOFMONTH(DATEADD('Dates'[Date],-1,MONTH)),ENDOFMONTH(DATEADD('Dates'[Date],-1,MONTH))
        ),
    BLANK ()
))

 

 

But this is giving me error and not working. Can anyone please help me on this?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi,@Anonymous 

I think you can use another DAX to calculate the total sales of previous month .

First ,you should create a Calendar Date table as a slicer to filter the Sales for product table .

 

Previous month total sales = CALCULATE(SUM('Sales for product'[sales]),PREVIOUSMONTH('Date'[Date]))

 

The effect is as shown:

Ailsa-msft_0-1616981031560.png

Ailsa-msft_1-1616981031562.png

Ailsa-msft_2-1616981031563.png

 

Best Regards

Community Support Team _ Ailsa Tao

 

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

4 REPLIES 4
Anonymous
Not applicable

Hi,@Anonymous 

I think you can use another DAX to calculate the total sales of previous month .

First ,you should create a Calendar Date table as a slicer to filter the Sales for product table .

 

Previous month total sales = CALCULATE(SUM('Sales for product'[sales]),PREVIOUSMONTH('Date'[Date]))

 

The effect is as shown:

Ailsa-msft_0-1616981031560.png

Ailsa-msft_1-1616981031562.png

Ailsa-msft_2-1616981031563.png

 

Best Regards

Community Support Team _ Ailsa Tao

 

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

Ashish_Mathur
Super User
Super User

Hi,

Does this measure work?

Month Saving = IF(COUNTROWS(Savings)>0,CALCULATE(SUM(Savings[Forecast Annual Cost Reduction - Use USD exchange rate of the day]),PREVIOUSMONTH('Dates'[Date])))

Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @Ashish_Mathur this is working but It populates values for all previous months of the date. What I want to do is to calculate the total sales in the previous month of current month and visualize it in Card or Guage visuals. 

Hi,

Try this measure

Month Saving = IF(COUNTROWS(Savings)>0,CALCULATE(SUM(Savings[Forecast Annual Cost Reduction - Use USD exchange rate of the day]),DATESBETWEEN('Dates'[Date],EOMONTH(TODAY(),-2)+1,EOMONTH(TODAY(),-1))))

Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors