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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
RT6
Frequent Visitor

same months comparison over the years - DAX

Hi all!

 

i use this DAX 

CY = CALCULATE(SUM('Market'[Sales]), DATESMTD('Calendar'[Date]))/1000;
 
and for the last year 
LY = CALCULATE(SUM('Market'[Sales]),DATESMTD(dateadd('Calendar'[Date],-1,YEAR)))/1000
 
the issue is when i select filter for example jan&feb 2024, it shows only value for February 2024 & 2023 accordingly. But i need a sum for of all selected months  
 
Any suggestions?
1 ACCEPTED SOLUTION
v-xuxinyi-msft
Community Support
Community Support

Hi @RT6 

 

Thanks for the reply from @Dangar332 , please allow me to provide another insight:

 

My sample:

vxuxinyimsft_0-1712730542611.png

 

vxuxinyimsft_1-1712730596323.png

 

Create a measure as follows

comparison = 
VAR _previous = CALCULATE(SUM(Market[Sales]), FILTER(Market, [Date] IN SAMEPERIODLASTYEAR('Calendar'[Date])))
VAR _current = CALCULATE(SUM(Market[Sales]), FILTER(ALL(Market), [Date] IN VALUES('Calendar'[Date])))
RETURN
DIVIDE(_previous + _current, 1000)

 

Result:

vxuxinyimsft_2-1712730733490.png

 

Best Regards,
Yulia Xu

 

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

3 REPLIES 3
v-xuxinyi-msft
Community Support
Community Support

Hi @RT6 

 

Thanks for the reply from @Dangar332 , please allow me to provide another insight:

 

My sample:

vxuxinyimsft_0-1712730542611.png

 

vxuxinyimsft_1-1712730596323.png

 

Create a measure as follows

comparison = 
VAR _previous = CALCULATE(SUM(Market[Sales]), FILTER(Market, [Date] IN SAMEPERIODLASTYEAR('Calendar'[Date])))
VAR _current = CALCULATE(SUM(Market[Sales]), FILTER(ALL(Market), [Date] IN VALUES('Calendar'[Date])))
RETURN
DIVIDE(_previous + _current, 1000)

 

Result:

vxuxinyimsft_2-1712730733490.png

 

Best Regards,
Yulia Xu

 

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

hi Yulia, 

 

thanks for your response! SAMEPERIODLASTYEAR worked well in this case 🙂

 

 

 

 

Dangar332
Super User
Super User

Hi, @RT6 

 you have slicer in month form and you want sum of month wise then use DATESYTD()

 

use DATESYTD instead of DATESMTD

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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