Forum Discussion

Quemi's avatar
Quemi
Frequent Visitor
4 years ago
Solved

Append and add rows with data if not found

Hi - I posted the other day and realized my target was unclear!   I want to append a row if not found, pull data over from Tables and add a flag column.   I have two tables, one with required val...
  • tackytechtom's avatar
    4 years ago

    Hi Quemi ,

     

    How about this:

     

    Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8shMz1DSUTIFYqfEPCBUitVBEfUvSsxLTwWL+uSXAwWMgTg8sSS1KDc1Jz8PWUIBqyEmSKKxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Group = _t, Time = _t, Fruit = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Group", type text}, {"Time", Int64.Type}, {"Fruit", type text}}),
        #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Group", "Time"}, Table16b, {"Group", "Time"}, "Table16b", JoinKind.LeftOuter),
        #"Expanded Table16b" = Table.ExpandTableColumn(#"Merged Queries", "Table16b", {"UniqueID", "Group", "Time", "Fruit"}, {"Table16b.UniqueID", "Table16b.Group", "Table16b.Time", "Table16b.Fruit"}),
        #"Added Custom" = Table.AddColumn(#"Expanded Table16b", "Flag", each if [Fruit] = [Table16b.Fruit] then "True" else "missing"),
        #"Reordered Columns" = Table.ReorderColumns(#"Added Custom",{"Table16b.UniqueID", "Group", "Time", "Fruit", "Flag", "Table16b.Group", "Table16b.Time", "Table16b.Fruit"}),
        #"Removed Columns" = Table.RemoveColumns(#"Reordered Columns",{"Table16b.Group", "Table16b.Time", "Table16b.Fruit"})
    in
        #"Removed Columns"

     

    Let me know if this solves your issue ๐Ÿ™‚

     

    /Tom
    https://www.tackytech.blog/
    https://www.instagram.com/tackytechtom/