Forum Discussion
a68tbird
7 years agoResolver II
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...
- 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
Greg_Deckler
7 years agoCommunity Champion
M would be the only way to go about inserting a new row, DAX doesn't do that. You would have to create an entirely new table with that row somehow included, perhaps by using something like GENERATESERIES or something. But better in M probably. There is a way to refer to the previous row in M but I can't remember it at the moment. ImkeF will know though.
ImkeF
7 years agoCommunity Champion
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