Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Iterate thru table - Adding row to all rows in a table

For each row in this table i want to add a new row and just change "belop" to "- whatever "belop" and Kontoart to "1".  I want to do this as a step in advanced editor.  Can anyone help me write the ...
  • v-yingjl's avatar
    v-yingjl
    5 years ago

    Hi Anonymous ,

    You can try this query:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnR0VNJRMgViQwOlWJ1oJScnJyDHEoiNIALOzs5AjjEIQwRcXFyAHDMgNoEIuLq6AjnmIHOAArEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Kontoart = _t, Belop = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Kontoart", Int64.Type}, {"Belop", Int64.Type}}),
        #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Name"}),
        #"Replaced Value" = Table.ReplaceValue(#"Removed Columns",each [Belop],each [Belop]*-1,Replacer.ReplaceValue,{"Belop"}),
        #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value",each [Kontoart],1,Replacer.ReplaceValue,{"Kontoart"}),
        #"Changed Type1" = Table.TransformColumnTypes(#"Replaced Value1",{{"Belop", Int64.Type}}),
        #"Append table" = Table.Combine({#"Changed Type", #"Changed Type1"})
    in
        #"Append table"

     

    Best Regards,
    Community Support Team _ Yingjie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.