I want to add data from the second query (Data) to the first query (Overview) depending on the information in the first query. I'll show my question with pictures to make it more clear. I have these two queries:
I want to add the "ITEM" information from the Data query to overview query looking up the "NAME.1" Column. I think I'm close to the solution because I can lookup the row with this formula:
=Data{[NAME.1=[NAME.1]]}
What do I need to add to the formula to only show the column "ITEM"? (and/or to show column number 0 in this case. Both solutions would be nice to understand it better how it works)
The data used in my screenshots:
Overview
| NAME.1 | NUMBER | RANDOM |
|---|---|---|
| Name1 | 243324 | qwsa |
| Name2 | 6747 | dsfsdf |
| Name3 | 455 | yyu |
| Name4 | 908098 | hfhn |
| Name5 | 34 | ertew |
| Name6 | 132 | uil |
| Name7 | 64 | tgvc |
| Name8 | 876 | iorts |
Data
| ITEM | Y/N | NAME.1 |
|---|---|---|
| 123123 | Y | Name5 |
| 234324 | Y | Name1 |
| 345345 | N | Name7 |
| 456456 | Y | Name2 |
| 567567 | N | Name8 |
| 678678 | N | Name3 |
| 789789 | Y | Name6 |
| 890890 | N | Name4 |
Some extra information in reply to the answer of Darren below
When using merge, is it also possible to to merge the ITEM information if NAME.1=NAME.1 and if there is no NAME.1 match, to look if there is a match in NAME.2=NAME.2? Possibly with the result in the same column.
Overview
| NAME.1 | NAME.2 | NUMBER | RANDOM |
|---|---|---|---|
| Name1 | 243324 | qwsa | |
| Name2 | 6747 | dsfsdf | |
| Name3 | 455 | yyu | |
| Name4 | 908098 | hfhn | |
| Name5 | 34 | ertew | |
| Name6 | 132 | uil | |
| Name7 | 64 | tgvc | |
| Name8 | 876 | iorts |
Data
| ITEM | Y/N | NAME.1 | NAME.2 |
|---|---|---|---|
| 123123 | Y | Name5 | |
| 234324 | Y | Name1 | |
| 345345 | N | Name7 | |
| 456456 | Y | Name2 | |
| 567567 | N | Name8 | |
| 678678 | N | Name3 | |
| 789789 | Y | Name6 | |
| 890890 | N | Name4 |
Some extra information in reply to the answer of Ron below
When I use =try Data{[NAME.1=[NAME.1]]}[ITEM] otherwise Data{[NAME.2=[NAME.2]]}[ITEM]) and my tables look like this:
Overview
| NAME.1 | NAME.2 | NUMBER | RANDOM |
|---|---|---|---|
| Name11 | 243324 | qwsa | |
| Name22 | 6747 | dsfsdf | |
| Name13 | 455 | yyu | |
| Name14 | 908098 | hfhn | |
| Name25 | 34 | ertew | |
| 132 | uil | ||
| 64 | tgvc | ||
| Name18 | 876 | iorts |
Data
| ITEM | Y/N | NAME.1 | NAME.2 |
|---|---|---|---|
| 123123 | Y | Name25 | |
| 234324 | Y | Name11 | |
| 345345 | N | Name17 | |
| 456456 | Y | Name12 | Name22 |
| 567567 | N | Name18 | |
| 678678 | N | Name13 | |
| 789789 | Y | Name16 | |
| 890890 | N | Name14 |
Then I will get the wrong information in the table:
The green highlighted is correct, the 3 yellow ones are wrong and should be null. I think I should add some kind of if null=null give null or something in that direction?
Some extra information in reply to the suggestion of Ron below
When I do merge I get this code:
let
Source = Excel.CurrentWorkbook(),
#"Filtered Rows" = Table.SelectRows(Source, each ([Name] = "Table1")),
#"Expanded Content" = Table.ExpandTableColumn(#"Filtered Rows", "Content", {"NAME", "NAME.2", "NUMBER", "RANDOM"}, {"NAME.1", "NAME.2", "NUMBER", "RANDOM"}),
#"Added Custom" = Table.AddColumn(#"Expanded Content", "AddInfoFromTable", each try Data{[NAME.1=[NAME.1]]}[ITEM] otherwise Data{[NAME.2=[NAME.2]]}[ITEM]),
#"Merged Queries" = Table.NestedJoin(#"Added Custom", {"NAME.1"}, Data, {"NAME.1"}, "Data", JoinKind.LeftOuter),
#"Expanded Data" = Table.ExpandTableColumn(#"Merged Queries", "Data", {"ITEM"}, {"ITEM"})
in
#"Expanded Data"
And modify the code in "Advanced Editor" to this, it still shows no error
let
Source = Excel.CurrentWorkbook(),
#"Filtered Rows" = Table.SelectRows(Source, each ([Name] = "Table1")),
#"Expanded Content" = Table.ExpandTableColumn(#"Filtered Rows", "Content", {"NAME", "NAME.2", "NUMBER", "RANDOM"}, {"NAME.1", "NAME.2", "NUMBER", "RANDOM"}),
#"Added Custom" = Table.AddColumn(#"Expanded Content", "AddInfoFromTable", each try Data{[NAME.1=[NAME.1]]}[ITEM] otherwise Data{[NAME.2=[NAME.2]]}[ITEM]),
#"Merged Queries" = Table.NestedJoin(#"Added Custom", {"NAME.1","NAME.2"}, Data, {"NAME.1","NAME.2"}, "Data", JoinKind.LeftOuter),
#"Expanded Data" = Table.ExpandTableColumn(#"Merged Queries", "Data", {"ITEM"}, {"ITEM"})
in
#"Expanded Data"`
However, I'm not sure what to do with these values in your suggestions:
{"ITEM", each [ITEM]{0}, Int64.Type})
in
Join
In my example the data in ITEM is numbers, in reality it contains a combination of numbers and letters (e.g., 0AB123 or AB123, etc.)










I believe the most efficient method is using the
Table.Joinfunction as demonstrated in another answer:However, your method can also work the way you want by merely adding the
Field Nameto your formula:Your posted data for this problem:

Overview
Data

Results

Edit: Given your additional information of having to compare Name.1 or Name.2, you can modify the
Table.Joinfunction as follows:Please note that this method requires that
NAME.1orNAME.2benull. If that is not the case, then coding would be more complexEdit2: Now with further information that either table might or might not have Names in none, one or both NAME.1 and NAME.2 cells, the following shows two different techniques of managing that situation which probably gives the results you want