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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Converting Month into custom Year column

Hi there. 

 

I have a table (Dates) that looks like this.

 

MonthYear 

Jan 2017

2017

Feb 20172017
May 20182018
September 20192019
February 20202020 (pre covid)
March 20202020 (post covid)
June 20202020 (post covid)
Jan 20212021

 

I am looking to create a column (in red) to explore the impact pre and post covid so that it will just give me the year for 2018, 2019 and 2021 but for 2020 it splits it into two i.e. Jan 2020 and Feb 2020 = 2020 (pre covid) and March 2020 onwards = 2020 (post covid)

 

Could anyone help with this as this is quite complex?

 

1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@Anonymous 

do you have a date column? if you have a date column, you can try this

year = if(year('Date'[Date])=2020 && month('Date'[Date]) in {1,2},"2020 pre covid",if(year('Date'[Date])=2020,"2020 post covid",FORMAT('Date'[Date],"yyyy")))




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

Proud to be a Super User!




View solution in original post

2 REPLIES 2
ryan_mayu
Super User
Super User

@Anonymous 

do you have a date column? if you have a date column, you can try this

year = if(year('Date'[Date])=2020 && month('Date'[Date]) in {1,2},"2020 pre covid",if(year('Date'[Date])=2020,"2020 post covid",FORMAT('Date'[Date],"yyyy")))




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

Proud to be a Super User!




Anonymous
Not applicable

@Anonymous Create next calculated columns:

'Year' - original year;

'Month' - month's number (january - 1, february - 2 etc.)

'customYear': SWITCH(TRUE(),

                       'Year'=2020&&'Month'<=2,"2020 (pre covid)",

                       'Year'=2020&&'Month'>2,"2020 (post covid)",

                       'Year')

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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