Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

ReplaceValue with multiple condition

Hi Im seeking for help on ReplaceValue query   I have a qeury table Item ID Size 2810-00131 150 3050-12568 150   I want to set  If [Item ID] = "2810-00131", then      if "Size" ...
  • v-frfei-msft's avatar
    6 years ago

    Hi Anonymous ,

     

    To add a custom column as below.

    if [Item ID] = "2810-00131" then if [Size] = 150 then 105 else then [Size]

     

     

    M code for your reference.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMrIwNNA1MDA0NlTSUTI0NVCK1YlWMjYwNdA1NDI1s4AJxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Item ID" = _t, Size = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Size", Int64.Type}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Item ID] = "2810-00131" and [Size] = 150 then 105 else [Size])
    in
        #"Added Custom"
  • Anonymous's avatar
    Anonymous
    6 years ago

    Thanks v-frfei-msft 

     

    I summarized your suggestion and create the working "Table.ReplaceValue" :

     

    #"Replaced Value" = Table.ReplaceValue(Source,each [Size],each if [Item ID]="2810-00131" and [Size]="150" then "105" else [Size],Replacer.ReplaceText,{"Size"})

     

     

    Regards,

    Henry