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

Previous month of last selected month if multiple months are selected

Hi,
I have column Date and Sales ,I need to show data on last selected month(last date) if multiple months are selected ans same for previous month 
Providing snap of dummy Data and expected result 

Prajakta11_0-1657278674206.png

if I select Jan-21,Feb-21,Mar-21
I want Current Month Sales as = 100 (data on last date of march)
Previous Month = 150 (data on last date of dec)


Can anyone pls suggest me how to solve this?

 

Thanks.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

Please check these formulas:

Current Month = 
var max_date = CALCULATE(MAX('Table'[date]),ALLSELECTED('Table'))
return
CALCULATE(SUM('Table'[sales]),FILTER(ALL('Table'),'Table'[date]=max_date))

Previous Month = 
var max_date = CALCULATE(MAX('Table'[date]),ALLSELECTED('Table'))
var count_months = DISTINCTCOUNT('Table'[Month year])
var pre_date = EDATE(max_date,-count_months)
return
CALCULATE(SUM('Table'[sales]),FILTER(ALL('Table'),'Table'[date]=pre_date))

vjaywmsft_1-1657604062083.png

 

Best Regards,

Jay

View solution in original post

9 REPLIES 9
Anonymous
Not applicable

its not working in my case Thanks for the reply

Anonymous
Not applicable

Hi @Anonymous ,

 

Please check these formulas:

Current Month = 
var max_date = CALCULATE(MAX('Table'[date]),ALLSELECTED('Table'))
return
CALCULATE(SUM('Table'[sales]),FILTER(ALL('Table'),'Table'[date]=max_date))

Previous Month = 
var max_date = CALCULATE(MAX('Table'[date]),ALLSELECTED('Table'))
var count_months = DISTINCTCOUNT('Table'[Month year])
var pre_date = EDATE(max_date,-count_months)
return
CALCULATE(SUM('Table'[sales]),FILTER(ALL('Table'),'Table'[date]=pre_date))

vjaywmsft_1-1657604062083.png

 

Best Regards,

Jay

Anonymous
Not applicable

Hi 

 

 

 

 

 

 

Hi @Anonymous ,
I have one more query ,I am unable to filter above calculated measure with other column ,
how can I resolve this

 

 

 

Anonymous
Not applicable

Hi @Anonymous ,

 

You can add the condition to the filter function.

For example:

CALCULATE(SUM('Table'[sales]),FILTER(ALL('Table'),'Table'[date]=max_date&&'table'[column]=selectedvalue(othercolumn)))

 

Best Regards,

Jay

Anonymous
Not applicable

Am I missing anything in this ? plus I want to filter two different column (i.e.platform and type )values  Capture2.PNG

Anonymous
Not applicable

Hi @Anonymous 
I have resolved filtering part ,using below measure it seems to work

Capture 3.PNG

 

 

 

 

but now I am not geting incorrect value if I am selecting last month as feb
as per my requirement it should give me data on sept 30 but it is giving value for sept 28 please refer blow image 
Capture 4.PNG


and It is working fine with other months selection only causing this issue if I am selecting feb as my latest month

Anonymous
Not applicable

Thaaaank You sooo much ....exactly the solution I needed!

Anonymous
Not applicable

Hi Amit,
Thanks for your Reply ,but its not working in my case I am sharing an Image with Deatiled Explaination 

Prajakta11_0-1657347679063.png

Firstly I have tried your DAX it is giving me Blank If I select single month.
and If I select Multilple Month as above Image It is till incorrect 
As I have selected (2019-03,2019-04) so what I want is , it should reflect (4198259)
Any help on this ?

amitchandak
Super User
Super User

@Anonymous , Try a month behind formula

Month behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Month))

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 PBI25 Carousel

Power BI Monthly Update - July 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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