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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
mariaorriols
Regular Visitor

Merge columns based on several values of one

Hi everyone, 

 

I have data since 2000, here I post a sample:

 

MonthQuarterYear
January 2020
February 2020
MarchQ12020
April 2020
May 2020
JuneQ22020
July 2020
August 2020
SeptemberQ32020
October 2020
November 2020
DecemberQ42020

 

I need to merge columns "Quarter" and "Year" but just when quarter equals Q1, Q2, Q3 or Q4. If quarter is empty, then the cell would remain empty:

 

MonthQuarterYearYear.Quarter
January 2020 
February 2020 
MarchQ120202020/Q1
April 2020 
May 2020 
JuneQ220202020/Q2
July 2020 
August 2020 
SeptemberQ320202020/Q3
October 2020 
November 2020 
DecemberQ420202020/Q4

 

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

Use this in a custom column

= if [Quarter]="" or [Quarter]=null then null else [Quarter]&"/"&Text.From([Year])

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("i45W8krMK00sqlTSUQIiIwMjA6VYnWglt9SkIizCvolFyRlAgUBDZFHHgqLMHAyV6Hq9SvNSQVqNUAVz0NU5lqaXFpegCQanFpSk5ialFoFMMEaW8U8uyYeII4v65ZfBlCMLu6Qmw00xgUvEAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Month = _t, Quarter = _t, Year = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Month", type text}, {"Quarter", type text}, {"Year", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Year.Quarter", each if [Quarter]="" or [Quarter]=null then null else [Quarter]&"/"&Text.From([Year]))
in
    #"Added Custom"

View solution in original post

1 REPLY 1
Vijay_A_Verma
Super User
Super User

Use this in a custom column

= if [Quarter]="" or [Quarter]=null then null else [Quarter]&"/"&Text.From([Year])

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("i45W8krMK00sqlTSUQIiIwMjA6VYnWglt9SkIizCvolFyRlAgUBDZFHHgqLMHAyV6Hq9SvNSQVqNUAVz0NU5lqaXFpegCQanFpSk5ialFoFMMEaW8U8uyYeII4v65ZfBlCMLu6Qmw00xgUvEAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Month = _t, Quarter = _t, Year = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Month", type text}, {"Quarter", type text}, {"Year", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Year.Quarter", each if [Quarter]="" or [Quarter]=null then null else [Quarter]&"/"&Text.From([Year]))
in
    #"Added Custom"

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.