Forum Discussion
Create a table where each row summarises column data from another table
Daniel, I'm afraid I don't understand the meaning of "col" in that. I want to use a column name, but List.Transform expects a list as the first argument. Both of the two "result" lines here give a table of "Error" for the two columns.
let
fn=(tbl,col)=>#table(Table.ColumnNames(tbl),{List.Transform(col,each List.Sum(Table.Column(tbl,_)))}),
col="First Column",
tbl = #table({"First Column", "Second Column"}, {{1,2},{3,4}}),
result = fn(tbl,"First Column")
//result = fn(tbl,Table.Column(tbl,"First Column"))
in result
I'd better give an example. Suppose I have a fn that returns a list of three items from a given list of values.
let
fn=(listofvalues)=>{List.Count(listofvalues),List.First(listofvalues),List.Last(listofvalues)},
col="First Column",
tbl = #table({"First Column", "Second Column"}, {{1,2},{1,4},{5,3}}),
result = fn(Table.Column(tbl,col))
in result
/* the fn gives me a list for ONE column's list of values:
List
3
1
5
I would like an expression which calls fn for each column in the table and returns a Table with one row for each source column and as many columns as values in the returned summary list, like this:
ColumnName Count First Last
First Column 3 1 5
Second Column 3 2 3
If it helps I could write fn as
fn=(listofvalues)=>[Count=List.Count(listofvalues),First=List.First(listofvalues),Last=List.Last(listofvalues)],
*/