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
mark77
Helper I
Helper I

DAX year comparison - Why does this not work?

Hi. I'm trying to set up a number of standard formula to be used in my PBI reports.

users are supposed to select 1 year. Also they can select additional filters such as YTD and whatever you have .

 

In any case :

Asume selected is (only) 2022 in the date filter.

 
(The following works)
TEST_TY =
VAR __YEARSELECTION = CALCULATE(MAX('Date'[Year])-0)
VAR __BASEFORMULA = CALCULATE([Product SO],FILTER('Date','Date'[Year]=__YEARSELECTION))
RETURN
__BASEFORMULA

 

(This does not - Except then selecting both 2022 AND 2021)

TEST_TY =
VAR __YEARSELECTION = CALCULATE(MAX('Date'[Year])-1)
VAR __BASEFORMULA = CALCULATE([Product SO],FILTER('Date','Date'[Year]=__YEARSELECTION))
RETURN
__BASEFORMULA

 

Why does the following above not work? How do I override the 2022 selection?

 

TEST = CALCULATE(sum(_actuals[product_sales_eur]),FILTER('Date','Date'[Year]=2021))  also does not work
Please not that I do not only want to look 1 year back, but will want to do 2020 aswell etc.
 
Thanks!

 

3 REPLIES 3
mark77
Helper I
Helper I

Can anyone help me with this?

amitchandak
Super User
Super User

@mark77 , You need to use all

 

TEST_TY =
VAR __YEARSELECTION = CALCULATE(MAX('Date'[Year])-1)
VAR __BASEFORMULA = CALCULATE([Product SO],FILTER(all('Date'),'Date'[Year]=__YEARSELECTION))
RETURN
__BASEFORMULA

 

Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
https://www.youtube.com/watch?v=km41KfM_0uA

 

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

 

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

Hi @amitchandak ,

 

Thank you for your response. Unfortunately this does not yield the required result. I had tested with all myself, but that will generate a grand total for me.

As you can see with the (modified) data here, the calculation falls apart in a table.

And I really do want to use a great many tables in many variants 😉

Do you know how I'd be able to resolve this ?

 

The Formula does respond correctly to filters though. For example a subcompany was selected here.

 

 

YTD_MMonthNameProduct SOTEST1_selfTEST_withall
YesOctober                                86,986                           8,215,746
YesNovember                             131,285                           8,215,746
YesDecember                             217,836                           8,215,746
YesJanuary                             792,691                           8,215,746
YesFebruary                          1,661,305                           8,215,746
YesMarch                          2,067,164                           8,215,746
YesApril                             956,637                           8,215,746
NoMay                             523,530                           8,215,746
NoJune                             386,022                           8,215,746
NoJuly                             453,112                           8,215,746
NoAugust                             288,973                           8,215,746
NoSeptember                                75,898                           8,215,746
 TOTAL                          7,641,440                           8,215,746

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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.