Forum Discussion
Record.TransformFields error
- 1 year ago
Hello, Mic1979 first of all, what problem are you trying to solve: the one in #1 or #6? I am lost. Lets take #6 (the one with tables). You are using wrong function/approach to transform column(s) values. Why Table.TransformRows and Record.TransformFields? There is Table.TransformColumns function.
I suggest that using record + Record.FieldOrDefault for a replacements is the "structure" you are talking about. Nothing wrong with it. It's the way you choose to apply it looks strange to me.
Okay, so be it - it's your decision. In my last message I just pointed out that list of column names (or list of single column name) should not be passed as table[column] as you suggested but as {"name1", "name2"} etc. Then you can easily setup transformations for Table.TransformColumns in the form of {{"name1", function1}, {"name2", function2}}
And even your current code works just fine if you pass {"Region"} instead of Starting_Table[Region] as you did.
your problem is not about the function, you have some other mistake
In Record.TransformFields Transformation should be in type function, so you can have to use a record in its first argument and then a list inculding the name of field and the transformation function. for example
= Record.TransformFields( [OrderID = 1, Price = 100], {"Price", (x)=> x/10} )
in the provided example, x reperesent value 100, so if you use it inside (x) => Record.FieldOrDefault(repl,x)}), it present null always (as it is equal to Record.FieldOrDefault(repl,200)
but the main problem is for the below notation, you cant use the name of step B4 at the end of that step, it will provide cycle
B4 = Record.TransformFields (Record_Region, {"Region", (x) => Record.FieldOrDefault(repl,x)})
][B4]
- AlienSx1 year agoSuper User
Omid_Motamedise wrote:but the main problem is for the below notation, you cant use the name of step B4 at the end of that step, it will provide cycle
B4 = Record.TransformFields (Record_Region, {"Region", (x) => Record.FieldOrDefault(repl,x)})
][B4]
fyi: Let expression
- Mic19791 year agoPost Partisan
Hello AlienSx,
so what is the problem? I am sure you have suggestions to solve it (this type of structure was suggested by you in another post), because I really don't understand while I get that type of error message.
Thanks a lot.
- AlienSx1 year agoSuper User
Hello, Mic1979 first of all, what problem are you trying to solve: the one in #1 or #6? I am lost. Lets take #6 (the one with tables). You are using wrong function/approach to transform column(s) values. Why Table.TransformRows and Record.TransformFields? There is Table.TransformColumns function.
I suggest that using record + Record.FieldOrDefault for a replacements is the "structure" you are talking about. Nothing wrong with it. It's the way you choose to apply it looks strange to me.
Okay, so be it - it's your decision. In my last message I just pointed out that list of column names (or list of single column name) should not be passed as table[column] as you suggested but as {"name1", "name2"} etc. Then you can easily setup transformations for Table.TransformColumns in the form of {{"name1", function1}, {"name2", function2}}
And even your current code works just fine if you pass {"Region"} instead of Starting_Table[Region] as you did.
- Omid_Motamedise1 year agoSuper User
Hi AlienSx
Thanks for sharing, I know that a record definition can be used instead of let/in expression, but what happened here is different, and is the mixed.
as I knwo, the below experision doesnt mean at all (b4 is the name of step, not the field name in the record).
let
b4=[........][b4]
in
b4- AlienSx1 year agoSuper User
Omid_Motamedise original code from message #1 does not have let ... in statement:
(replacements) => [ // generates a record with replacements repl = Function.Invoke(Record.FromList, List.Reverse(Table.ToColumns(replacements))), Record_Region = [ Region = { "AM.", "EMEA", "APAC" }, Step = { "A", "B", "C" } ], B4 = Record.TransformFields (Record_Region, {"Region", (x) => Record.FieldOrDefault(repl,x)}) ][B4]so that nothing is wrong with
[b4 = "some_value"][b4]