Forum Discussion

GianJo's avatar
GianJo
New Member
3 years ago
Solved

Replace Value with previous Row based on a condition

Hello everybody,   I am trying to replace a value based on a condition. If the condition is true I want to replace the value with the one in the previous Row. I am using Table.replaceValue but I ma...
  • latimeria's avatar
    3 years ago

    Hi GianJo ,

     

    Almost there, "Replacer.ReplaceText" replace text selected whereas "Replacer.ReplaceValue" replace the value

    Table.ReplaceValue(
            AggiuntaColonnaIndice,
            each [ClasseProva],
            each if [ClasseProva] = "ciao"
            then
            AggiuntaColonnaIndice{[Indice]}[ClasseProva]
            else
            [ClasseProva],
            Replacer.ReplaceValue,{"ClasseProva"})

     Now, if you create your Index from 0, you can do:

    = Table.ReplaceValue(
            AggiuntaColonnaIndice,
            each [ClasseProva],
            each if [ClasseProva] = "ciao"
            then
            AggiuntaColonnaIndice{[Indice]-1}[ClasseProva]
            else
            [ClasseProva],
            Replacer.ReplaceValue,{"ClasseProva"})

     and its clearer in my mind you are getting previous row.