Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Expression.Error: We cannot convert the value to type List

Hi all,   I have a collection of data that I am trying to adjust to break cumulative numbers down into specific period numbers. To this extent I've written the following code:   #"Specific Column...
  • Nolock's avatar
    Nolock
    7 years ago

    Hi Anonymous,

    the problem is in addressing the row.

    #"Specific Column" = Table.AddColumn(#"Changed Type4","Specific", each if [Column1]{[Index]-1} = [Column1]{[Index]-2} and [Column2]{[Index]-1} = [Column2]{[Index]-2} then [Amount]{[Index]-1} - [Amount]{[Index]-2} else [Amount]{[Index]-1})

    "Each" interates over all rows and gives you a current row in every step. And it means, that [Column1] is a text value in current row and you access (Index-1)th character of the string, what you actually don't want. Therefore the error, that a text isn't a list.

    A suggestion is for example followings:

    = Table.AddColumn(#"Changed Type 4", "Previous Row", each #"Changed Type 4"[Column1]{[Index] - 1})

    It addresses the column Column1 of (index-1)th row of the table #"Changed Type 4".

    Btw. not sure how performant it is, but it works for sure