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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
bendsteel6
Helper I
Helper I

Put current and previous year in column titles

Hi,

I'm trying to create column headers in a table visual that would simply read "Adjusted $ YTD (2024)" and "Adjusted $ YTD (2023)", but instead of hardcoding '2024' and '2023', I would like to place the year dynamically.  This way when I don't have to change the column headers in 2025, etc.  Note: I will always be using 'current year' and 'previous year' data. 

Is this simple to do?  I have not yet found a post that does this.

Thanks!

1 ACCEPTED SOLUTION
Sahir_Maharaj
Super User
Super User

Hello @bendsteel6,

 

Can you please try this:

 

1. Create Measures for Current Year and Previous Year

AdjustedYTD_CurrentYear = 
VAR CurrentYear = YEAR(TODAY())
RETURN 
CALCULATE(
    SUM('Sales Table'[Amount]),
    YEAR('Sales Table'[Date]) = CurrentYear
)
AdjustedYTD_PreviousYear = 
VAR PreviousYear = YEAR(TODAY()) - 1
RETURN 
CALCULATE(
    SUM('Sales Table'[Amount]),
    YEAR('Sales Table'[Date]) = PreviousYear
)

2. Add Dynamic Labels to the Measures

AdjustedYTD_CurrentYear_Label = 
"Adjusted $ YTD (" & YEAR(TODAY()) & ")"
AdjustedYTD_PreviousYear_Label = 
"Adjusted $ YTD (" & YEAR(TODAY()) - 1 & ")"

Hope this helps.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

View solution in original post

2 REPLIES 2
bendsteel6
Helper I
Helper I

Hi,

Thanks for this!  Really appreciate it!

Sahir_Maharaj
Super User
Super User

Hello @bendsteel6,

 

Can you please try this:

 

1. Create Measures for Current Year and Previous Year

AdjustedYTD_CurrentYear = 
VAR CurrentYear = YEAR(TODAY())
RETURN 
CALCULATE(
    SUM('Sales Table'[Amount]),
    YEAR('Sales Table'[Date]) = CurrentYear
)
AdjustedYTD_PreviousYear = 
VAR PreviousYear = YEAR(TODAY()) - 1
RETURN 
CALCULATE(
    SUM('Sales Table'[Amount]),
    YEAR('Sales Table'[Date]) = PreviousYear
)

2. Add Dynamic Labels to the Measures

AdjustedYTD_CurrentYear_Label = 
"Adjusted $ YTD (" & YEAR(TODAY()) & ")"
AdjustedYTD_PreviousYear_Label = 
"Adjusted $ YTD (" & YEAR(TODAY()) - 1 & ")"

Hope this helps.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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