Power Query中带除法运算的IF条件语句配置问题
Power Query 条件计算问题

我尝试在Power Query中编写IF条件语句,需求如下:
- 当UOM为
Btl且最小数量(Min Quantity)为0时,直接返回单价(Unit Price) - 当UOM为
Btl且最小数量不为0时,用单价除以最小数量 - 当UOM不等于
Btl时,用单价除以装箱数(Case Pack)
不清楚自己哪里出现了问题。
解决方案
你可以用Power Query的M语言嵌套if语句实现该逻辑,公式如下:
= if [UOM] = "Btl" then if [Min Quantity] = 0 then [Unit Price] else [Unit Price] / [Min Quantity] else [Unit Price] / [Case Pack]
关键注意点:
- 需确保公式中的列名与数据表中的列名完全匹配(包括空格、大小写),否则会引用失败
- 若存在除数为0的场景(比如非Btl类型时
Case Pack为0),可添加容错逻辑避免报错:
= if [UOM] = "Btl" then if [Min Quantity] = 0 then [Unit Price] else if [Min Quantity] <> 0 then [Unit Price] / [Min Quantity] else null else if [Case Pack] <> 0 then [Unit Price] / [Case Pack] else null
内容的提问来源于stack exchange,提问作者seannn21
相关产品推荐
相关产品推荐

