Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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)
Group | Time | Fruit |
High | 5 | Banana |
High | 5 | Orange |
Low | 3 | Watermelon |
Low | 3 | Banana |
High | 4 | Banana |
Table 2 (Obtained Values):
UniqueID | Group | Time | Fruit |
A64 | High | 5 | Banana |
B32 | High | 5 | Orange |
B34 | Low | 3 | Watermelon |
C64 | High | 4 | Banana |
Table 3: Desired Output -- Append with Unique ID + expected Group/Time/Fruit and Flag. Font color to show what I would like to append
UniqueID | Group | Time | Fruit | Flag |
A64 | High | 5 | Banana | True |
A64 | High | 5 | Orange | Missing |
B32 | High | 5 | Banana | Missing |
B32 | High | 5 | Orange | True |
B34 | Low | 3 | Watermelon | True |
B34 | Low | 3 | Banana | Missing |
C64 | High | 4 | Banana | True |
Solved! Go to Solution.
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/
Did I answer your question❓➡️ Please, mark my post as a solution ✔️ |
Also happily accepting Kudos 🙂 |
Feel free to connect with me on LinkedIn! | |
#proudtobeasuperuser | |
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! | |
#proudtobeasuperuser | |
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/
Did I answer your question❓➡️ Please, mark my post as a solution ✔️ |
Also happily accepting Kudos 🙂 |
Feel free to connect with me on 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! | |
#proudtobeasuperuser | |
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
10 | |
7 | |
7 | |
6 | |
6 |