Replace Value from one column based on a condition from another column [Power Query]

Viewed 1131

Hello this is my first post!

I'm trying to replace the word "OTROS" from the column Origen based on the condition that the column Marca has the value "X-1000". I'm following this video: https://youtu.be/XpZTPEBHQOY?t=81

However when I try to execute the following code in the Power Query bar nothing happens

= Table.ReplaceValue(#"Changed Type", 
each [Origen], 
each if [Marca] = "X-1000" then "CHINA" else [Origen], 
Replacer.ReplaceValue,{"Origen"})

Table image

I tried refreshing and doing it again but nothing happens. Thanks a lot in advanced for any help.

1 Answers

The code works perfectly, it is how you are using it

updated answer :: Based on comments your column has a space in the column name

You needed to use [#"Marca "] instead of [Marca]

change your code to

let
Source = Csv.Document(File.Contents("C:\Users\RAD\Downloads\Parque Vehicular.csv"),[Delimiter=",", Columns=9, Encoding=1252, QuoteStyle=QuoteStyle.None]),
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Año Inscripción", Int64.Type}, {"Mes Inscripción", Int64.Type}, {"Año Entrada", Int64.Type}, {"Descripción Clase", type text}, {"Tipo", type text}, {"Año Fabricación", Int64.Type}, {"Origen", type text}, {"Marca ", type text}, {"Cantidad", Int64.Type}}),
#"Replaced Value" = Table.ReplaceValue(#"Changed Type", each [Origen], each if [#"Marca "] = "X-1000" then "CHINA" else [Origen], Replacer.ReplaceValue,{"Origen"})
in #"Replaced Value"
Related