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

View all the Fabric Data Days sessions on demand. View schedule

Reply
TracyHT
New Member

Need help to automate the year change in PBI measure

Hello Power BI community,

I have a question regarding the automation of year change in my PBI measures. 

Here is the link to download my sample workbook https://drive.google.com/file/d/1V-aJWENneBT4TlCo4ZyWK0RW9IRE7jVa/view?usp=share_link

 

Currently, in the measure named "Test", I used a specific year (such as 2022) to illustrate the idea that when it is the current year, the measure shows Total YTD figures while in historical years, it shows full-year data (disregard the year slicer). The weakness of this measure is the manual change of year 202x in the "Test" measure when it comes to a new year.

TracyHT_0-1672684542936.png

 

I am thinking that I can replace 2022 with the formula year(today()) but the problem is that in January 2023 we started consolidating data of December 2022, and if I replace 2022 with year(today()), I would not be able to use month slicer to interact with YTD figures in 2022.

 

Does anyone have any idea how I can automatically replace the manual change of year (which is 2022 in the sample data)?

 

Many thanks in advance and Happy new year to everyone in our community.

2 REPLIES 2
amitchandak
Super User
Super User

@TracyHT , One of the way to get YTD based on today

 

YTD Today =
var _min = eomonth(today(),-1*month(today()))+1
var _max = today()
return
CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

 

 

Based on selected date of today

 

YTD =
var _max = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _min = eomonth(_max,-1*MONTH(_max))+1
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

 

 

You can put additional conditions to have YTD this year after Jan

 

example

YTD Today =

var _max1 = today()

Var _max - if(month(_max1) =1, eomonth(_max1,-1) , _max1)
var _min = eomonth(_max ,-1*month(_max ))+1

return
CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

 

 

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

@amitchandak Thank you for your solution but I'm not really clear.

Does that mean I should create 3 more measures? Should I replace "2022" in my measure with the measure below?

 

You can put additional conditions to have YTD this year after Jan

 

example

YTD Today =

var _max1 = today()

Var _max - if(month(_max1) =1, eomonth(_max1,-1) , _max1)
var _min = eomonth(_max ,-1*month(_max ))+1

return
CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors