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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
FLYKOBE24
Regular Visitor

New column based off values from two existing columns

Hello, 

 

I am trying to replicate this SQL query in Power BI power query. 

 

 Replace([WBS],"XXXX",[Task Name]) AS WBSTask, Timesheet_Entries_T.WBS,
 
Basically i want a new column that takes the values from my column WBS and replaces the XXXX with the values from my Task Name Column
 
RESULT:
 
WBS: 1.21.01A.XXXX-700 Task Name: PM40 New Column: 1.21.01A.PM40-700 
 
1 ACCEPTED SOLUTION
ronrsnfld
Super User
Super User

Paste the code below into the Advanced Editor. The magic happens at the #"Add New Column" step.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQzMtQzMHTUqwACXXMDAyUdpQBfEwOl2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [WBS = _t, #"Task Name" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"WBS", type text}, {"Task Name", type text}}),
    #"Add New Column" = Table.AddColumn(#"Changed Type","New Column", 
        each Text.BeforeDelimiter([WBS],"xxxx") & [Task Name] & Text.AfterDelimiter([WBS],"xxxx"), type text)
in
    #"Add New Column"

 

ronrsnfld_0-1731633311137.png

See also the Add Custom Column:

ronrsnfld_1-1731633385328.png

 

 

 

View solution in original post

3 REPLIES 3
ronrsnfld
Super User
Super User

Paste the code below into the Advanced Editor. The magic happens at the #"Add New Column" step.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQzMtQzMHTUqwACXXMDAyUdpQBfEwOl2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [WBS = _t, #"Task Name" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"WBS", type text}, {"Task Name", type text}}),
    #"Add New Column" = Table.AddColumn(#"Changed Type","New Column", 
        each Text.BeforeDelimiter([WBS],"xxxx") & [Task Name] & Text.AfterDelimiter([WBS],"xxxx"), type text)
in
    #"Add New Column"

 

ronrsnfld_0-1731633311137.png

See also the Add Custom Column:

ronrsnfld_1-1731633385328.png

 

 

 

Thank you very much @ronrsnfld worked great!!!!

 

Wow alot more to it than i thought the SQL syntax is much easier.

 

I appreciate your help. 

You can use syntax similar to SQL:

 

Text.Replace([WBS],"xxxx","Task Name")

 

However, using the diagnostic tools available in Power BI, that syntax runs considerably slower than the more complicated version I presented.

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors