Forum Discussion
Adding index column in ADF Power Query
- 2 years ago
Hi and welcome to the Fabric Data Factory community forum. This forum is specific to the Fabric Data Factory experience.
For questions related to Azure Data Factory you can use the Azure Data Factort community forum using the link below:
https://techcommunity.microsoft.com/t5/azure-data-factory/bd-p/AzureDataFactory
There are limitations on the integration that Power Query has in ADF.
Power Query activity in Azure Data Factory - Azure Data Factory | Microsoft Learn
Heavily inspired by Re: Adding index column in ADF Power Query - Microsoft Fabric Community:
let
MyTable = Table.FromRecords({
[Name="Alice", Age="30", Country="USA"],
[Name="Bob", Age=null, Country="UK"],
[Name="Charlie", Age="35", Country=null]
},
type table[Name = Text.Type, Age = Text.Type, Country = Text.Type]
),
IndexList = List.Numbers(1, Table.RowCount(MyTable)),
TableFromColumns = Table.FromColumns({MyTable[Name], MyTable[Age], MyTable[Country], IndexList}, type table[Name = Text.Type, Age = Int64.Type, Country = Text.Type, Index = Int64.Type])
in
TableFromColumns
or
let
MyTable = Table.FromRecords({
[Name="Alice", Age="30", Country="USA"],
[Name="Bob", Age=null, Country="UK"],
[Name="Charlie", Age="35", Country=null]
}),
IndexList = List.Numbers(1, Table.RowCount(MyTable)),
TableFromColumns = Table.FromColumns(Table.ToColumns(MyTable) & {IndexList}, Table.ColumnNames(MyTable) & {"Index"})
in
TableFromColumns
(this second alternative means you don't need to specify the selected column names from MyTable inside the TableFromColumns. Instead, you select the whole table.)
Heavily inspired by Power Query - Combine tables without Merging 🔗🧲 (youtube.com):
(Also with this alternative, you don't need to specify the column names when combining the two tables.)
let
MyTable = Table.FromRecords({
[Name="Alice", Age="30", Country="USA"],
[Name="Bob", Age=null, Country="UK"],
[Name="Charlie", Age="35", Country=null]
}
),
IndexList = List.Numbers(1, Table.RowCount(MyTable)),
IndexListAsTable = Table.FromList(IndexList, Splitter.SplitByNothing(), {"Index"}, null, ExtraValues.Error),
TableToColumns = Table.PromoteHeaders(Table.FromColumns(Table.ToColumns(Table.DemoteHeaders(MyTable)) & Table.ToColumns(Table.DemoteHeaders(IndexListAsTable))))
in
TableToColumns
Heavily inspired by Solved: Re: Merge tables without a join, placing new colum... - Microsoft Fabric Community:
(This uses quite different functions from the previous examples.
Also, you don't need to specify the column names when combining the two tables.)
let
MyTable = Table.FromRecords({
[Name="Alice", Age="30", Country="USA"],
[Name="Bob", Age=null, Country="UK"],
[Name="Charlie", Age="35", Country=null]
}
),
MyTableTransposed = Table.Transpose(Table.DemoteHeaders(MyTable)),
IndexList = List.Numbers(1, Table.RowCount(MyTable)),
IndexListAsTable = Table.FromList(IndexList, Splitter.SplitByNothing(), {"Index"}, null, ExtraValues.Error),
IndexTransposed = Table.Transpose(Table.DemoteHeaders(IndexListAsTable)),
AppendTables = Table.Combine({MyTableTransposed, IndexTransposed}),
TransposeAppendedTables = Table.Transpose(AppendTables),
#"Promoted Headers" = Table.PromoteHeaders(TransposeAppendedTables, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Name", type text}, {"Age", Int64.Type}, {"Country", type text}, {"Index", Int64.Type}})
in
#"Changed Type"
These seem like interesting ways to just add a column to a table in Power Query without using a join condition.
I haven't checked if any of these will work in ADF Power Query, though.