合并表后,里面有一些 字段 ,下面全部显示null ,或者0,想用Table.removecolumns 这个函数自动删除 这些列,语句怎么写,求解?
合并表后,里面有一些 字段 ,下面全部显示null ,或者0,想用Table.removecolumns 这个函数自动删除 这些列,语句怎么写,求解?
考虑筛选不包含0, null等的列形成的list的步骤 = List.Select( List.Transform(Table.ColumnNames(源), (x)=>Table.SelectColumns(源, x)), each List.Transform(Table.ToColumns(_),(y)=>List.RemoveItems(y, {0,"0",null,"null",""}) ){0}<>{} ),试写出自定义函数如下——
(t as table)=>[
a=List.Select(
List.Transform(Table.ColumnNames(t), (x)=>Table.SelectColumns(t, x)), each List.Transform(
Table.ToColumns(_), (y)=>
List.RemoveItems(y, {0,"0",null,"null",""}) ){0}<>{} ),
b=List.Transform(
List.Zip(
List.Transform(a, each Table.ToRows(_))),List.Combine),
c= List.Combine(
List.Transform(a, Table.ColumnNames)), d=Table.FromRows(b, c)
][d]
或者添加如下步骤
= List.Accumulate(
List.Combine(
List.Transform(
List.Select(
List.Transform(Table.ColumnNames(源), (x)=>Table.SelectColumns(源, x)), each List.Transform(Table.ToColumns(_), (y)=>
List.RemoveItems(y, {0, "0", null,"null", ""}) ){0}={} ), Table.ColumnNames)),
源,
(s, c)=>Table.RemoveColumns(s, c))
降级标题 转置 筛选行 再转置, 点点鼠标就完成了。
table.removecolumns(source,list.select(table.columnnames(source),each list.nonullcount(table.column(source,_))=0))
table.removecolumns(source,list.select(table.columnnames(source),each list.removeitems(table.column(source,_),{null,0})={}))