自动展开所有“表格列"具有特定名称 [英] Automatically Expand all "Table Columns" with specific name

查看:13
本文介绍了自动展开所有“表格列"具有特定名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编码初学者,不熟悉M"建模语言.我有一个 XML 文件,我想用它来在查询编辑器中加载数据.在查询中,我只需要扩展下面具有特定名称的表列:

  1. 查看
  2. 视图文件夹
  3. 属性:名称

我找到了以下

解决方案

您应该能够简单地在旧的 ColumnsToExpand 行上放置一个过滤器.

也就是说,

 TableColumns =//这是旧的 ColumnsToExpand 定义重命名.List.Distinct(List.Combine(List.Transform(ColumnContents, each if _ is table then Table.ColumnNames(_) else {}))),ColumnsToExpand =List.Select(TableColumns, each (_ = "view" or _ = "viewfolder" or _ = "Attribute:name")),

或者像这样在一行中,

 ColumsToExpand = List.Select(List.Distinct(List.Combine(List.Transform(ColumnContents, each if _ is table then Table.ColumnNames(_) else {}))), each (_ = "view" 或 _ = "viewfolder" 或 _ = "Attribute:name")),

I'm a beginner in coding and am not familiar with "M" modeling language. I have an XML file that I want to use to load the data in Query Editor. In the Query, I need to expand only the table columns with a specific name below:

  1. view
  2. viewfolder
  3. Attribute:name

I have found the following post where they give a function by Chris Webb for expanding all the lists(below code).

= (TableToExpand as table, optional ColumnNumber as number) =>
    let
     ActualColumnNumber = if (ColumnNumber=null) then 0 else ColumnNumber,
     ColumnName = Table.ColumnNames(TableToExpand){ActualColumnNumber},
     ColumnContents = Table.Column(TableToExpand, ColumnName),
     ColumnsToExpand = List.Distinct(List.Combine(List.Transform(ColumnContents, each if _ is table then Table.ColumnNames(_) else {}))),
     NewColumnNames = List.Transform(ColumnsToExpand, each ColumnName & "." & _),
     CanExpandCurrentColumn = List.Count(ColumnsToExpand)>0,
     ExpandedTable = if CanExpandCurrentColumn then Table.ExpandTableColumn(TableToExpand, ColumnName, ColumnsToExpand, NewColumnNames) else TableToExpand,
     NextColumnNumber = if CanExpandCurrentColumn then ActualColumnNumber else ActualColumnNumber+1,
     OutputTable = if NextColumnNumber>(Table.ColumnCount(ExpandedTable)-1) then ExpandedTable else ExpandAll(ExpandedTable, NextColumnNumber)
    in
     OutputTable

But how to expand only desired lists/tables?

解决方案

You should be able to simply put a filter on the old ColumnsToExpand line.

That is,

 TableColumns = //This is the old ColumnsToExpand definition renamed.
     List.Distinct(List.Combine(List.Transform(ColumnContents, each if _ is table then Table.ColumnNames(_) else {}))),
 ColumnsToExpand =
     List.Select(TableColumns, each (_ = "view" or _ = "viewfolder" or _ = "Attribute:name")),

Or in one line like this,

 ColumsToExpand = List.Select(List.Distinct(List.Combine(List.Transform(ColumnContents, each if _ is table then Table.ColumnNames(_) else {}))), each (_ = "view" or _ = "viewfolder" or _ = "Attribute:name")),

这篇关于自动展开所有“表格列"具有特定名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆