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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Anonymous
Not applicable

Calculating Quantity Sold last month & two months ago?

Hello, 
 
I am trying to calculate total quantity sold the last month and two months ago, but it is giving me wrong quantity. Can anybody please tell me whats wrong or take a look at my sample file. I really appreciate your help. 
 
Formula - 
 
One Month Ago = CALCULATE([Total Sold Quantity], DATEADD('Date'[Day], -1,MONTH))
Two Month Ago = CALCULATE([Total Sold Quantity], DATEADD(TestDataForSales[Day], -2,MONTH))
 
 
Thank you so much 
 
 
1 ACCEPTED SOLUTION
v-danhe-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous,

Based on my test, you can refer to below steps:

1.Create two measures to create your “one month ago data” and the “two month ago data”

New One month ago = CALCULATE (

                SUM(TestDataForSales[Quantity]),

                PARALLELPERIOD('TestDataForSales'[Day],-1,MONTH))-

    CALCULATE (

                SUM(TestDataForSales[Quantity]),

                PARALLELPERIOD('TestDataForSales'[Day],-2,MONTH))

New Two month ago = CALCULATE (

                SUM(TestDataForSales[Quantity]),

                PARALLELPERIOD('TestDataForSales'[Day],-2,MONTH))-

    CALCULATE (

                SUM(TestDataForSales[Quantity]),

                PARALLELPERIOD('TestDataForSales'[Day],-3,MONTH))

2.Create a Table visual and add the [Products], [SKU], [New One month ago] and [New Two month ago] fields.

1.PNG

3.Create two card visuals and add the [New One month ago] and [New Two month ago] fields.

2.PNG

Now you can see the result.

C.PNG

You can also download the PBIX file to have a view.

https://www.dropbox.com/s/q4l1cjnor65nzgp/Calculating%20Quantity%20Sold%20last%20month%20%26%20two%20months%20ago.pbix?dl=0

 

Regards,

Daniel He

Community Support Team _ Daniel He
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

5 REPLIES 5
v-danhe-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous,

Based on my test, you can refer to below steps:

1.Create two measures to create your “one month ago data” and the “two month ago data”

New One month ago = CALCULATE (

                SUM(TestDataForSales[Quantity]),

                PARALLELPERIOD('TestDataForSales'[Day],-1,MONTH))-

    CALCULATE (

                SUM(TestDataForSales[Quantity]),

                PARALLELPERIOD('TestDataForSales'[Day],-2,MONTH))

New Two month ago = CALCULATE (

                SUM(TestDataForSales[Quantity]),

                PARALLELPERIOD('TestDataForSales'[Day],-2,MONTH))-

    CALCULATE (

                SUM(TestDataForSales[Quantity]),

                PARALLELPERIOD('TestDataForSales'[Day],-3,MONTH))

2.Create a Table visual and add the [Products], [SKU], [New One month ago] and [New Two month ago] fields.

1.PNG

3.Create two card visuals and add the [New One month ago] and [New Two month ago] fields.

2.PNG

Now you can see the result.

C.PNG

You can also download the PBIX file to have a view.

https://www.dropbox.com/s/q4l1cjnor65nzgp/Calculating%20Quantity%20Sold%20last%20month%20%26%20two%20months%20ago.pbix?dl=0

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

This solution worked for me as well but it is very resource intensive on large sets of data. It takes ages to refresh the dataset when this measure is added to a visual. 

Anonymous
Not applicable

@v-danhe-msft

 

Hello, 

 

This works and it makes sense.  Thank you so much for the time and help. 

 

Anonymous
Not applicable

i dont see any issues with your formula .

 

I hope your total sold qty is SUM( QTY) to make your calculation as shown below.

 

CALCULATE(SUM(Sales.Quanity_sold),DATEADD(Dates[Date],-1,MONTH)

 

Due to my access issues in laptop, am unable to download your file. Please make sure your measures are aggregating properly and relationship are set properly.

 

Thanks

Raj

Anonymous
Not applicable

@Anonymous

Hello, 

 

Thank you for the help and time.  We have to minus months. 

 

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.