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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
mariaorriols
Regular Visitor

Merge columns based on values

Hi everyone

 

My data looks like (all of them are text type): 

 

Month1MonthYear
01

January

2022
02February2022
03March2022
04April2022
05May2022

 

I am only showing these months of 2022, but I have data since 2005. 

I want to create a new column, Month.Year, that combines both "Month" and "Year" if Month equals "Gener". If else it should state just Month. So it would look like:

 

Month1MonthYearMonth.Year
01

January

2022January 2022
02February2022February
03March2022March
04April2022April
05May2022May
06June2022June
07

July

2022

July

08August2022August
09September2022September
10October2022October
11November2022November
12December2022December
01January2021January 2021
1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

Use following formula in a custom column

 

= if Number.From([Month1])=1 then [Month]&" "&Text.From([Year]) else [Month]

 

 See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfJKzCtNLKoEsowMjIyUYnWilYyAHLfUpCJ0cWMgxzexKDkDWdAEyHEsKMrMQRY0BatEaI4FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Month1 = _t, Month = _t, Year = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Month.Year", each if Number.From([Month1])=1 then [Month]&" "&Text.From([Year]) else [Month])
in
    #"Added Custom"

 

View solution in original post

1 REPLY 1
Vijay_A_Verma
Super User
Super User

Use following formula in a custom column

 

= if Number.From([Month1])=1 then [Month]&" "&Text.From([Year]) else [Month]

 

 See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfJKzCtNLKoEsowMjIyUYnWilYyAHLfUpCJ0cWMgxzexKDkDWdAEyHEsKMrMQRY0BatEaI4FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Month1 = _t, Month = _t, Year = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Month.Year", each if Number.From([Month1])=1 then [Month]&" "&Text.From([Year]) else [Month])
in
    #"Added Custom"

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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