Forum Discussion

drogzy's avatar
drogzy
Helper I
4 years ago
Solved

How to replace a value in column A only based on another value in column B while in direct query

Hello,    Here is what I have:    Column A Column B Development Original Observation Original Development Re-entry Development Other Abandon Original Observation  Orig...
  • Vijay_A_Verma's avatar
    4 years ago

    Use this (Replace #"Changed Type" with your previous step)

    = Table.ReplaceValue(#"Changed Type",each [Column B], each if [Column A]="Development" then  "Developing" else [Column B], Replacer.ReplaceValue,{"Column B"})

     

  • Vijay_A_Verma's avatar
    Vijay_A_Verma
    4 years ago

    See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately)

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WckktS83JL8hNzStR0lHyL8pMz8xLzFGK1YlW8k8qTi0qSyzJzM9Dl0LVFZSqC2QUVWKR8i/JSC0CizsmJealYJqEZIkCilwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Column A" = _t, #"Column B" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column A", type text}, {"Column B", type text}}),
        Custom1 = Table.ReplaceValue(#"Changed Type",each [Column B], each if [Column A]="Development" then  "Developing" else [Column B], Replacer.ReplaceValue,{"Column B"})
    in
        Custom1