Forum Discussion
Dicken
Post Prodigy
1 year agofunction behavior
I have a question ragarding function behavior, I made a mistake and used table,column rathrer than record.field, so example table ; #table( type table [ A = Text.Type , Unit = Any.Type] , {{"A"...
- 1 year ago
Hi again Dicken
I did ask around some contacts. The general opinion is that it some sort of "leakage" of the internal representation of tables as either lists of records or records of lists. It shouldn't stricly behave this way but Power Query is erroneously allowing it in this case.
Another intriguing variation is this (credit to Greg Baldini )
let Source = #table(type table [Col1 = Text.Type, Col2 = Int64.Type], {{"A", 2}, {"B", 3}, {"C", 4}}), // this step yields an error for every row in "Col3" in the query preview AddColumn = Table.AddColumn(Source, "Col3", each Table.Column(_, "Col2"), Int64.Type), // this step does not yield an error, but crazier: it *undoes* the error in the prior step. // the preview here yields a "Col3" and a "NewCol" both of which have *no* errors. AddColumnWithTableColumn = Table.AddColumn(AddColumn, "NewCol", each Table.Column(_, "Col2"), Int64.Type) in AddColumnWithTableColumnI'll give some feedback to Microsoft when I have a chance. Feel free to do the same 🙂
Dicken
Post Prodigy
1 year agoThanks,
as I said i came across by accident, I did linkedin post giving this as an exampel ;
let
sourcetab = #table(type table [A = Any.Type, Unit = Any.Type], {{"a", 2}, {"b", 3}}),
pfunc = (atab as table, acol as text) =>
Table.AddColumn(atab, "N", each Table.Column(_, acol) / List.Sum(Table.Column(atab, acol))),
result1 = pfunc(sourcetab, "Unit"),
result2 = pfunc(Table.AddColumn(sourcetab, "New", (x) => 1), "Unit")
in
result2At least i can now accept it as 'one of those things' and stop obsessing about it.
Thanks, again,
Richard