【发布时间】:2019-02-21 19:31:25
【问题描述】:
寻找Max Zelensky's 解决方案here 的后续行动。假设原始示例有一个 [Date] 字段,我正在尝试再上一层并添加一个显示先前 [Date] 值的列
-
Per Max,我已经创建了表格:
AddedCustom = Table.AddColumn(GroupedRows, "Custom", each Table.AddIndexColumn([tmp],"Occurrence", 1,1) type table)
-
创建了第二个索引:
SecondIndex= Table.AddColumn(AddedCustom, "Custom.2", each Table.AddIndexColumn([Custom],"Occurance.2", 0,1), type table)
-
我已成功添加引用当前 [Date] 行的列:
CurrentDate= Table.AddColumn(SecondIndex, "Date.2", each Table.AddColumn([Custom.2],"Date.2", each [Date]), type table)
-
但是,当我尝试引用任一索引列(甚至只是放入 {0})时,新字段就会出错。我相当确定我在一列表格中引用表格中的行的语法中遗漏了一些东西,但我只是不确定如何到达那里 - 我尝试过的一些示例没有成功:
PriorDate= Table.AddColumn(SecondIndex, "PriorDate", each Table.AddColumn([Custom.2],"Prior Date", each {0}[Date]), type table)-- 看看能不能返回第一行的值PriorDate= Table.AddColumn(SecondIndex, "PriorDate", each Table.AddColumn([Custom.2],"Prior Date", each {[Occurance.2]}[Date]), type table)-- 不适用于 [Occurance] 或 [Occurance.2]PriorDate= Table.AddColumn(SecondIndex, "PriorDate", each Table.AddColumn([Custom.2],"Prior Date", each {[Occurance]-1}[Date]), type table)PriorDate= Table.AddColumn(SecondIndex, "PriorDate", each Table.AddColumn([Custom.2],"Prior Date", each [Custom.2]{0}[Date]), type table)PriorDate= Table.AddColumn(SecondIndex, "PriorDate", each Table.AddColumn([Custom.2],"Prior Date", each Table.SelectColums([Custom.2],[Date])), type table)
另外,任何人都可以向我指出优化#Tables、{Lists}、[Records] 等的语法和机制的良好参考。我将不胜感激(我已经阅读了 Ken Puls 的书的第 20 章次,但它还没有完全卡住)。提前致谢!
| Name | Date | Occurance | Prior Date (Desired) |
|------|----------|-----------|----------------------|
| A | 1/1/2019 | 1 | null/error |
| A | 3/1/2019 | 2 | 1/1/2019 |
| B | 2/1/2019 | 1 | null/error |
| A | 4/1/2019 | 3 | 3/1/2019 |
| B | 5/1/2019 | 2 | 2/1/2019 |
【问题讨论】:
-
这是一个很好的问题,但是如果您可以在起始数据表的示例表中进行编辑以及您期望的结果,将会得到很大的改进。
-
Alexis- 很抱歉将表格添加为 html,我将提高我的降价技能并更新帖子
-
我为你修好了。
-
谢谢。 (尝试)
标签: powerbi powerquery m