MrDark
MrDark

Reputation: 67

How can I get a column value from previous row in Power Query?

I want to get a value from the previous row.

I tried the following code as suggested in this post:

Table.AddColumn(#"Added index", "custom column", each {[Index]-1}[column name])

But it throws this error:

Cannot use field access fot type List

Please help, what am I doing wrong?

Upvotes: 1

Views: 20497

Answers (1)

Carl Walsh
Carl Walsh

Reputation: 7009

The error comes because {[Index]-1} without anything before it is a list value, but instead you want to index into a row of a table with this syntax: MyTable{index}

That looks like:

= Table.AddColumn(#"Added index", "custom column", each #"Added index"{[Index]-1}[My Column])

Upvotes: 11

Related Questions