我正在努力只获取每张票证的最后一个非空白值。
在 Power Pivot 测量中,我使用了函数 LASTNONBLANK()
,但结果并不可靠 - 可能是因为数据模型没有考虑行的原始顺序。
Excel 公式或 VBA 不是一个选项,我认为在 Power Query
中效率不会很高。
对于票证“1”,返回值应为“b”(步骤 4),对于票证“2”,返回值应为“a”(步骤 5)。
最佳答案
特别是由于数据已排序,因此在 Power Query 中非常简单:
- 删除空白值行
- 按票号分组
- 返回每组中的最后一个值
(如果没有排序,您只需为 Group 中的每个子表添加排序即可)
M代码
let
Source = Excel.CurrentWorkbook(){[Name="Table28"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{
{"ticket", Int64.Type},
{"step", Int64.Type},
{"timestamp", type datetime},
{"value", type text}}),
#"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([value] <> null)),
#"Grouped Rows" = Table.Group(#"Filtered Rows", {"ticket"}, {
{"Last Non-Blank", each List.Last([value])}
})
in
#"Grouped Rows"
关于Excel数据模型: Return last non blank,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68618645/