Power Query删除指定行遇问题:Table.SelectRows查询返回空行求解析
问题分析与解决方案
错误原因
你写的查询返回零行,是因为Power Query中布尔值与数字不能直接等价比较:
- 当你写
(sub_id=1 and amount=19000) = 0时,sub_id=1 and amount=19000会返回布尔值true或false,但Power Query不会把true等同于1、false等同于0,所以这个比较对所有行都会返回false,Table.SelectRows会过滤掉所有符合true的行(也就是没有行被保留),最终返回空表。
正确写法
要删除sub_id=1且amount=19000的行,只需要保留不满足该条件的行,有两种等价写法:
写法1:直接取反条件
用not关键字对目标条件取反:
Table.SelectRows(#"ABC", each not (sub_id=1 and amount=19000))
写法2:逻辑上排除目标行
通过逻辑或,保留sub_id不等于1或者amount不等于19000的行:
Table.SelectRows(#"ABC", each sub_id <> 1 or amount <> 19000)
验证结果
执行上述任意一种写法后,返回的数据表会是:
| sub_id | amount | status | stateid |
|---|---|---|---|
| 1 | 15000 | 2 | true |
| 1 | 15000 | 4 | true |
内容的提问来源于stack exchange,提问作者Punitha
相关产品推荐
相关产品推荐

