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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
SanderTK
Advocate II
Advocate II

Adding index column in ADF Power Query

Hi everyone,

 

At the moment I am trying to work around Spark M-code restrictions to create an index column within Data Factory's Power Query.

While the option to add an index column is present in the interface, when used it will return the error:

"Expression.Error: The Power Query Spark Runtime does not support the function Table.AddIndexColumn."

 

I am now trying to use a Power Query formula in "add custom column" to create an index column based on row count.

It is succesful in creating a table with one index column but it is then impossible to join/merge that table to the table which is in need of an index column (there is no join condition since the table contains only the one column).

 

M-Script.png

It is also possible to create an index column as a "Table.AddColumn" but this gives several errors and results in an indexing of every record in that table for the amount of records in that table (so with 7 rows, it will create 7 rows for every one of those rows and gives them an index from 1 to 7).

 

Result.png

 

I feel like I'm getting close to a viable work-around but I am missing something to implement it succesfully.

 

Any and all help will be much appreciated!

4 REPLIES 4
p45cal
Solution Supplier
Solution Supplier

Re:

While the option to add an index column is present in the interface, when used it will return the error:

"Expression.Error: The Power Query Spark Runtime does not support the function Table.AddIndexColumn."

 

It's a bit of a surpise that it's in the interface and then fails; I wonder if it's a legacy thing: PQ added an argument to AddIndexColumn, being the last one, the data type. Try missing it out, ie:

Instead of:

= Table.AddIndexColumn(PreviousStep, "Index", 1, 1, Int64.Type)

try:

= Table.AddIndexColumn(PreviousStep, "Index", 1, 1)

p45cal
Solution Supplier
Solution Supplier

Starting with a table (Table1) with a single column headed stuff:

let 
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
AddedIndex = Table.FromColumns({Source[stuff],{1..Table.RowCount(Source)}},{"stuff","Index"})
in 
AddedIndex

 

p45cal
Solution Supplier
Solution Supplier

Further, if you have more than 1 column in your table you can try:

 

 

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
AddIndex=Table.FromColumns(Table.ToColumns(Source) & {{1..Table.RowCount(Source)}}, Table.ColumnNames(Source) & {"Index"})
in
AddIndex

 

 

 

The technique behind this works perfectly, however, ADF still gives an error about the dataset being dynamic in length which it cannot handle. I currently can't get the exact wording of the error because I get an internal server error when trying to load datasets into ADF power query. 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors