首页 > 解决方案 > 有什么方法可以在 PowerQuery 中移动“单元格”?

问题描述

我有多个需要分析的 CSV 文件,在顶行中有两条识别信息。下面的下一行是空白的。第三行包含标题。如何创建 2 个自定义列,其中包含从顶行向下复制到下面所有 100 多行数据的“单元格”4 和 6?Excel VBA 很简单,但是这个数据集将被永久使用,以后的用户可能不会懂 VBA。(感谢亚历克西斯的桌子!!)

| Probe | 503     | SN:1256 | 8/27/2020 | 13:23 | AUG20  | BH02     |
|-------|---------|---------|-----------|-------|--------|----------|
|       |         |         |           |       |        |          |
| Tube# | Tube ID | MC #    | A B Cal   | Units | STD MC | Ratio    |
| 1     | 8       |  1      |           |       |        |          |
| 1     | 1       | -1      | Count     | 7403  | 1493   | 0.201675 |
| 2     | 1       | -1      | Count     | 7403  | 1486   | 0.200729 |
| 3     | 1       | -1      | Count     | 7403  | 1686   | 0.227746 |
| 4     | 1       | -1      | Count     | 7403  | 1705   | 0.230312 |
| 5     | 1       | -1      | Count     | 7403  | 1779   | 0.240308 |
| 6     | 1       | -1      | Count     | 7403  | 1954   | 0.263947 |
| 7     | 1       | -1      | Count     | 7403  | 1965   | 0.265433 |

标签: excelvbapowerquery

解决方案


发布样本数据。

像这样的东西,假设没有列标题开始,会拉出第一行,并转换为剩余数据的列

// get the first two columns of first row
TopRow1 = Table.First(#"PreviousStep")[Column1],
TopRow2 = Table.First(#"PreviousStep")[Column2],
// remove first row
#"Removed Top Rows" = Table.Skip(#"PreviousStep",1),
// convert new first row to column headers
#"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true]),
// custom columns to add the data we found above
#"Added Custom" = Table.AddColumn(#"Promoted Headers", "TopRow1", each TopRow1),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "TopRow2", each TopRow2)

推荐阅读