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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
KH_Mike
Helper III
Helper III

DAX Year on Year Calculation

Hi All,

 

I have a table like below and try to use below DAX to calculate last year record for Year on Year comparison.

 

Last Year =
var LY=SELECTEDVALUE(Table[Year])-1
Return
CALCULATE(sum(Table[Volume]),Table[Year]=LY)


When I use the slicer to select Year = 2021

The DAX formula will show 120. However, what I want to show is 40 because Year 2021 only contain 1, 2, 3, 4 in Month. Thank you.

 

YearMonthVolume
2020110
2020

2

10
2020310
2020410
2020510
2020610
2020710
2020810
2020910
20201010
20201110
20201210
2021110
2021210
2021310
2021410

 

1 ACCEPTED SOLUTION
Nathaniel_C
Community Champion
Community Champion

Hi @KH_Mike , try this:


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel

Last Year = 
var LY=SELECTEDVALUE(myTable[Year])-1
var TY= Selectedvalue(myTable[Year])
var _maxMonth = CALCULATE(MAX(myTable[Month]),myTable[Year]=TY)
var _calc = CALCULATE(sum(myTable[Volume]),myTable[Year]=LY && myTable[Month]<=_maxMonth)




Return _calc




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

5 REPLIES 5
Nathaniel_C
Community Champion
Community Champion

Hi @KH_Mike , try this:


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel

Last Year = 
var LY=SELECTEDVALUE(myTable[Year])-1
var TY= Selectedvalue(myTable[Year])
var _maxMonth = CALCULATE(MAX(myTable[Month]),myTable[Year]=TY)
var _calc = CALCULATE(sum(myTable[Volume]),myTable[Year]=LY && myTable[Month]<=_maxMonth)




Return _calc




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




CNENFRNL
Community Champion
Community Champion

Construct a Date column in order to leverage time intelligence functions,

Screenshot 2021-06-02 054227.png

Screenshot 2021-06-02 054720.pngScreenshot 2021-06-02 054153.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Hi @CNENFRNL 

 

Is there any option to acheive the same result? I don't want to creat new column for this issue. Thank you.

Hi @KH_Mike ,
Like this?

Nathaniel_C_0-1622642204328.png


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi @Nathaniel_C 

 

Yes. Can you share me the DAX? Thank you.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.