Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Quemi
Frequent Visitor

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 values at a minimum for, and one with a Unique Variable + obtained values -- The Unique Variable MUST have all "fruits" for the Group + Time, if the unique variable does not contain the requried value(s), I would like to append a row with the Unique ID + Missing values along with a Flaged column.

 

Table 1 (required values)

GroupTimeFruit
High5Banana
High5Orange
Low3Watermelon
LowBanana
High4Banana

 

 Table 2 (Obtained Values):

UniqueIDGroupTimeFruit
A64High5Banana
B32High5Orange
B34Low3Watermelon
C64High4Banana

 

Table 3: Desired Output   -- Append with Unique ID + expected Group/Time/Fruit and Flag. Font color to show what I would like to append

UniqueIDGroupTimeFruitFlag
A64High5BananaTrue
A64High5OrangeMissing
B32High5Banana

Missing

B32High5Orange

True

B34Low3Watermelon

True

B34LowBananaMissing
C64High4BananaTrue
2 ACCEPTED SOLUTIONS
tackytechtom
Super User
Super User

Hi @Quemi ,

 

How about this:

tomfox_0-1650044563988.png

 

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/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

Hi @Quemi ,

 

I am glad I could help! Do not forget to mark the answer as a solution, so people can find it quicker in future 🙂

 

Regarding your question, it is something that Power BI creates anytime you add data via the "enter data" function. Here more on this:

Power Query Enter Data Explained. There are many things you do so often… | by Nolock | Medium

 

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



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

3 REPLIES 3
tackytechtom
Super User
Super User

Hi @Quemi ,

 

How about this:

tomfox_0-1650044563988.png

 

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/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

This works, thank you so much!!!

 

Super new power query user (recently changed from a mac), most of the code makes sense, but for future info - what does the binary from text mean --> how is the FromText("145...A==") derived ? 

Hi @Quemi ,

 

I am glad I could help! Do not forget to mark the answer as a solution, so people can find it quicker in future 🙂

 

Regarding your question, it is something that Power BI creates anytime you add data via the "enter data" function. Here more on this:

Power Query Enter Data Explained. There are many things you do so often… | by Nolock | Medium

 

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



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.