From here i am creating Table with column lists for each table:
TableName|List
Table1
Table2
And now i have query (which will be the function so i need dynamic variable for tableName) like here:
let
TableName = "Table1",
Source = TableName,
ColumnsToRemove = Table.Column(TableName, "List"){0} //not working --> i need just take the list from TableList to get all columns which i have to keep in Table1 - in this case Col1 and Col2
// table.RemoveColumns(Source,ColumnsToRemove)
in
ColumnsToRemove
So i want to refer to TableList and get List of columns which i have to keep, all other i want to delete.
So in this example Table1 has one additional column which is called "AdditionalOne".
I do not want to have this column in result.
But how to take the list of columns from TableList to keep ?
How to build funtion in order to make this dynamically?
In other words: how to get column names from TableList based on selected table (filter TableList?), how to create ListOfColumnsToKeep variable dynamically?
Source= Excel.CurrentWorkbook(){[Name=TableName]}[Content] returns a table where the table name is provided by the parameter TableName.
Your LastShape step has 2 problems:
LastShape= Table.SelectColumns(TableName, ColumnsToKeep) : Both parameters used are wrong: TableName is not a table, ColumnsToKeep is nowhere in your code, where is this coming from? ColumnsToKeep is supposed to be a list...
As mentioned in your previous topics, a table column is a list.
You have to refer to a single column from a table to get a list of items in that column.
If you just put the column name at the end of a step, the result of that step is a list, no longer a table:
#"Filter" = Table.SelectRows(#"Grouped Rows", each ([TableName] = TableName))[ColumnName]
Make sure in that column you have values, not other objects like tables, the image you attached shows you have tables in the List column, if you refer to that column, you'll get a list of tables, not a list of strings...
Ok i got it but still struggling with changing table to list type 🙂
let
TableName = "Table1",
Source = TableList,
#"Grouped Rows" = Table.Group(Source, {"TableName"}, {{"ColumnsToKeep", each _, type table [TableName=nullable text, List=table]}}),
#"List" = Table.AddColumn(#"Grouped Rows", "List", each Table.Column([ColumnsToKeep],"ColumnName")),
#"Filter" = Table.SelectRows(#"Added Custom", each ([TableName] = TableName))
in
#"Filter"
I am getting error while creating #"List" step... Literally the result in table is just "Error" for each row for the column.
Why? What i am doing wrongly?
Hmm i was trying to add column and create list from Table.
The syntax is:
Table.Column(table as table, column as text) as list i have no idea what should be there.
I tried with:
#"List" = Table.AddColumn(#"Grouped Rows", "List", each [ColumnsToKeep]),
but it is creating Table instead of list.
Can you please help?
You are chasing your own tail and I have no idea what you're trying to do.
Which is the table you are trying to remove columns from?
#"Grouped Rows" step does not make any sense, because the Source is TableList, which is a grouped table. Why grouping again a grouped table, does not make any sense.