You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 05:45:56