Forum Discussion

a68tbird's avatar
a68tbird
Resolver II
7 years ago
Solved

Conditionally Insert Row

tl;dr - ForEach columnProduct = foo, Table.InsertRow, Fill Down, Replace columnProduct = foo2 in new row.   Hello All,   I'd like to insert a new row to my table only when columnProduct = foo. The...
  • ImkeF's avatar
    ImkeF
    7 years ago

    You can do it like this:

     

    • Filter your table where Product = "foo"
    • replace product name
    • append to source

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSsvPV9JRMgRiE6VYnWilvHyIiBEQm0JFoELGQGymFBsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Product = _t, Column2 = _t, Column1 = _t]),
        FilterFooProducts = Table.SelectRows(Source, each ([Product] = "foo")),
        ReplaceProductName = Table.ReplaceValue(FilterFooProducts,"foo","foo2",Replacer.ReplaceText,{"Product"}),
        AppendToSource = Source & ReplaceProductName
    in
        AppendToSource