Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel Power查询中的条件列标题_Excel_Powerquery - Fatal编程技术网

Excel Power查询中的条件列标题

Excel Power查询中的条件列标题,excel,powerquery,Excel,Powerquery,我遇到的情况是,由于我的数据具有键和文本格式,其中有一个列标题可用于键,但不可用于文本,因此某些列缺少标题标题。下面是一个例子 我希望为每一列定义标题,这样即使我更改了数据集的位置,逻辑也能工作。在excel中,我按照图2所示进行操作 结果如图3所示 目前我正在使用PowerQuery,我对这个工具还很陌生。有人知道哪些步骤可以解决这个问题吗?因此,即使数据源的位置发生变化,列标题仍然可以在excel中正常工作。我很高兴。这里有一个可能的解决方案: 在Excel中,将表格加载到Power查询中

我遇到的情况是,由于我的数据具有键和文本格式,其中有一个列标题可用于键,但不可用于文本,因此某些列缺少标题标题。下面是一个例子

我希望为每一列定义标题,这样即使我更改了数据集的位置,逻辑也能工作。在excel中,我按照图2所示进行操作

结果如图3所示


目前我正在使用PowerQuery,我对这个工具还很陌生。有人知道哪些步骤可以解决这个问题吗?因此,即使数据源的位置发生变化,列标题仍然可以在excel中正常工作。我很高兴。

这里有一个可能的解决方案:

在Excel中,将表格加载到Power查询中,取消选中“我的表格有标题”:

在Power Query editor中,查找高级编辑器,然后复制并粘贴以下行:

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type any}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}, {"Column6", type text}, {"Column7", type text}, {"Column8", type any}, {"Column9", type any}, {"Column10", type any}}),
    #"Transposed Table" = Table.Transpose(#"Changed Type"),
    #"Added Conditional Column" = Table.AddColumn(#"Transposed Table", "Custom", each if [Column1] = null then [Column2] else [Column1]),
    #"Duplicated Column" = Table.DuplicateColumn(#"Added Conditional Column", "Custom", "Custom - Copy"),
    #"Filled Down" = Table.FillDown(#"Duplicated Column",{"Custom"}),
    #"Added Conditional Column1" = Table.AddColumn(#"Filled Down", "Custom.1", each if [#"Custom - Copy"] = null then [Custom] & " Name" else [Custom]),
    #"Reordered Columns" = Table.ReorderColumns(#"Added Conditional Column1",{"Custom.1", "Column1", "Column2", "Column3", "Column4", "Column5", "Custom", "Custom - Copy"}),
    #"Removed Columns" = Table.RemoveColumns(#"Reordered Columns",{"Column1", "Custom", "Custom - Copy"}),
    #"Transposed Table1" = Table.Transpose(#"Removed Columns"),
    #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table1", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"StudentID", type any}, {"Country", type text}, {"Country Name", type text}, {"Department", type text}, {"Department Name", type text}, {"Mayor", type text}, {"Mayor Name", type text}, {"AGE", type any}, {"WEIGHT", type any}, {"HEIGHT", type any}})
in
    #"Changed Type1"
在Excel中加载为表格:


不客气,请接受我的回答。这将有助于提高我的声誉: