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
Mquallet
New Member

Set Value of Column B based on Value in Column A

Two columns, A and B in same table.
A has names of classes in it.  B is their category
If colA contains certain words = '*open chat*' id like to set colB to 'Chat", else leave it alone.

 

Simplest manner to accomplish this?

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @Mquallet ,

According to your description, here's my solution.

#"Transform"=Table.ReplaceValue(#"Changed Type",each[ColumnB],each if Text.Contains([ColumnA],"*open chat*") then "Chat" else[ColumnB],Replacer.ReplaceValue,{"ColumnB"})

I create a sample and get the correct result:

vkalyjmsft_0-1669355532328.png

Here's the whole M syntax, you can copy-paste it in a blank query to see the details.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W0sovSM1TSM5ILNFS0lFyU4rViVZyBrLcwSwXIMsDzHJFVeilFBsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ColumnA = _t, ColumnB = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ColumnA", type text}, {"ColumnB", type text}}),
    #"Transform"=Table.ReplaceValue(#"Changed Type",each[ColumnB],each if Text.Contains([ColumnA],"*open chat*") then "Chat" else[ColumnB],Replacer.ReplaceValue,{"ColumnB"})
in
    #"Transform"

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-yanjiang-msft
Community Support
Community Support

Hi @Mquallet ,

According to your description, here's my solution.

#"Transform"=Table.ReplaceValue(#"Changed Type",each[ColumnB],each if Text.Contains([ColumnA],"*open chat*") then "Chat" else[ColumnB],Replacer.ReplaceValue,{"ColumnB"})

I create a sample and get the correct result:

vkalyjmsft_0-1669355532328.png

Here's the whole M syntax, you can copy-paste it in a blank query to see the details.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W0sovSM1TSM5ILNFS0lFyU4rViVZyBrLcwSwXIMsDzHJFVeilFBsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ColumnA = _t, ColumnB = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ColumnA", type text}, {"ColumnB", type text}}),
    #"Transform"=Table.ReplaceValue(#"Changed Type",each[ColumnB],each if Text.Contains([ColumnA],"*open chat*") then "Chat" else[ColumnB],Replacer.ReplaceValue,{"ColumnB"})
in
    #"Transform"

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

wdx223_Daniel
Super User
Super User

NewStep=Table.ReplaceValue(PreviousStepName,"open chat",each [colA],(x,y,z)=>if Text.Contains(z,y) then "Chat" else x,{"colB"})

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.

Top Solution Authors
Top Kudoed Authors