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
Anmolgan
Post Prodigy
Post Prodigy

How to concatenate two columns together in Edit Queries?

I have a below dataset:

 

SAP State Names      My State Names

A1                                  A1

A2                                  A2

A3                                  B3

A4                                  B4

A5       

A6

 

i want to merge both the fields in such a way that values that do not match SAP State Names Column from My State Names should get replaced with My State Names entries and where ever there is a blank then reeplace SAP State names with the blanks for My Statee Names, output should look like below:

 

Custom Column

A1

A2

B3

B4

A5

A6

 

is there any way to achive this using custom columns or edit queries??

1 ACCEPTED SOLUTION

@Anmolgan - remove the columns that created the calculated column?

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjRU0gERsTpAthGIbQRhGwPZTsYQtgmIbQJhmwLZEJYZmBULAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"SAP State Names" = _t, #"My state Names" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"SAP State Names", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [My state Names] <> "" then [My state Names] else [SAP State Names]),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"})
in
    #"Removed Other Columns"





Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



View solution in original post

6 REPLIES 6
ChrisMendoza
Resident Rockstar
Resident Rockstar

@Anmolgan -

 

image.png

 

= Table.AddColumn(#"Changed Type", "Custom", each if [My state Names] <> "" then [My state Names] else [SAP State Names])

 






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



@ChrisMendoza This gives me a merged table and not the respective output

@Anmolgan - remove the columns that created the calculated column?

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjRU0gERsTpAthGIbQRhGwPZTsYQtgmIbQJhmwLZEJYZmBULAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"SAP State Names" = _t, #"My state Names" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"SAP State Names", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [My state Names] <> "" then [My state Names] else [SAP State Names]),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"})
in
    #"Removed Other Columns"





Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



kentyler
Solution Sage
Solution Sage

Your logic could be boiled down to just showing the SAP State Names.

If you have cases where you have a state name that is not in SAP State Names then you might need a calculated column with some IF() statements.





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


Can you elaborate more @kentyler 

you said

values that do not match SAP State Names Column from My State Names should get replaced with My State Names entries and where ever there is a blank then reeplace SAP State names with the blanks for My Statee Names, 

this means that anytime there is a value in the SAP State Names column it falls under one of your 2 conditions....

so the values in your custom column will always be the same values that you have in your state names column





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


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.