Forum Discussion
How can I use a conditional statement in a custom function referencing a specific column?
- 3 years ago
Hi Anonymous,
Just replace COL_LEFT in TO_2 to Record.Field(_ , COL_LEFT{0}). You are passing the list(with column names) , the first item should be the name of the column that you want to add the "_not_found" to.
Cheers,
John
:Are you going to replace the values in 1 column at a time? If yes, you can convert this custom column approach to a custom function.
Yes, Anonymous . I just don't know how to write such function š
Struggled here all day long trying to replace the 'hardcoded' names with variables but didn't succed.
Hi Anonymous
I see, here is one way, though TAB_FROM_TO is not used, but easier to explain...
(TAB_ORIGIN as table,
TAB_FROM_TO as table,
COL_LEFT as text,
COL_RIGHT as list,
COL_EXTRACTED as list) =>
let
#"Added Custom" = Table.AddColumn(TAB_ORIGIN, "Custom", each
[original = Record.FieldValues(Record.SelectFields(_, {COL_LEFT})){0}?,
a=try COL_EXTRACTED{List.PositionOf(COL_RIGHT, original)} otherwise original&"_not found"][a]),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{COL_LEFT}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", COL_LEFT}})
in
#"Renamed Columns"
- Anonymous3 years agoNot applicable
Hello Anonymous,
It returned 'not found' for all records.
I guess it has to do with the fact that there is no reference to the lookup table, isn't it?
lookup table:
function call:
let Fonte = Excel.CurrentWorkbook(){[Name="BASE"]}[Content], #"Tipo Alterado" = Table.TransformColumnTypes(Fonte,{{"Original A", type text}, {"Original B", type text}}), BulkReplace = BulkReplace3 ( #"Tipo Alterado", DE_PARA, "Original A", {"De"}, {"Para"} ) in BulkReplace