Nhảy tới nội dung

Table.NestedJoin

Performs a join between tables on supplied columns and produces the join result in a new column.

Syntax

Table.NestedJoin(
table1 as table,
key1 as any,
table2 as any,
key2 as any,
newColumnName as text,
optional joinKind as JoinKind.Type,
optional keyEqualityComparers as list
) as table

Remarks

Joins the rows of table1 with the rows of table2 based on the equality of the values of the key columns selected by key1 (for table1) and key2 (for table2). The results are entered into the column named newColumnName.
The optional joinKind specifies the kind of join to perform. By default, a left outer join is performed if a joinKind is not specified.
An optional set of keyEqualityComparers may be included to specify how to compare the key columns. This feature is currently intended for internal use only.

Examples

Example #1

Join two tables using a single key column.

Table.NestedJoin(
Table.FromRecords({
[CustomerToCall = 1],
[CustomerToCall = 3]
}),
{"CustomerToCall"},
Table.FromRecords({
[CustomerID = 1, Name = "Bob", Phone = "123-4567"],
[CustomerID = 2, Name = "Jim", Phone = "987-6543"],
[CustomerID = 3, Name = "Paul", Phone = "543-7890"],
[CustomerID = 4, Name = "Ringo", Phone = "232-1550"]
}),
{"CustomerID"},
"CustomerDetails"
)

Result:

Table.FromRecords({
[CustomerToCall = 1, CustomerDetails = Table.FromRecords({[CustomerID = 1, Name = "Bob", Phone = "123-4567"]})],
[CustomerToCall = 3, CustomerDetails = Table.FromRecords({[CustomerID = 3, Name = "Paul", Phone = "543-7890"]})]
})

Category

Table.Transformation

More Examples

shared Employees = let
Source = Sql.Databases(DbServer),
AdventureWorks = Source{[Name="AdventureWorks"]}[Data],
HumanResources_Employee = AdventureWorks{[Schema="HumanResources",Item="Employee"]}[Data],
#"Removed Columns" = Table.RemoveColumns(HumanResources_Employee,{"HumanResources.Employee(EmployeeID)", "HumanResources.Employee(ManagerID)", "HumanResources.EmployeeAddress", "HumanResources.EmployeeDepartmentHistory", "HumanResources.EmployeePayHistory", "HumanResources.JobCandidate", "Person.Contact", "Purchasing.PurchaseOrderHeader", "Sales.SalesPerson"}),
#"Merged Queries" = Table.NestedJoin(#"Removed Columns",{"ContactID"},Contacts,{"ContactID"},"Contacts",JoinKind.LeftOuter),
#"Expanded Contacts" = Table.ExpandTableColumn(#"Merged Queries", "Contacts", {"EmailAddress"}, {"EmailAddress"})
in
#"Expanded Contacts";