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

Azure Data Flow中获取上一年指定日期及派生列嵌套IF配置方法

Azure Data Flow 派生列条件表达式实现

直接使用以下表达式即可满足你的需求:

(DateColumn1 >= addYears(trunc(utcNow(), 'year'), -1)) && ((DateColumn2 < addMonths(addYears(trunc(utcNow(), 'year'), -1), 1)) || isNull(DateColumn2)) ? 'true' : 'false'

表达式拆解说明:

  • 上一年1月1日的构造:addYears(trunc(utcNow(), 'year'), -1)
    • utcNow() 获取当前UTC时间
    • trunc(utcNow(), 'year') 将当前时间截断到当年1月1日
    • addYears(..., -1) 对截断后的日期减1年,得到上一年1月1日
  • 上一年2月1日的构造:addMonths(addYears(trunc(utcNow(), 'year'), -1), 1)
    • 在上述上一年1月1日的基础上,调用addMonths(..., 1)加1个月,得到上一年2月1日
  • 条件逻辑:
    • 先判断DateColumn1 >= 上一年1月1日
    • 再判断DateColumn2 < 上一年2月1日 或者 DateColumn2为空(isNull(DateColumn2))
    • 用&&和括号确保逻辑优先级,当两个条件同时满足时返回'true',否则返回'false'

备选方案(基于字符串构造日期)

如果更习惯用字符串拼接方式生成目标日期,也可以用以下表达式:

(DateColumn1 >= toDate(concat(string(year(utcNow())-1), '-01-01'))) && ((DateColumn2 < toDate(concat(string(year(utcNow())-1), '-02-01'))) || isNull(DateColumn2)) ? 'true' : 'false'

内容的提问来源于stack exchange,提问作者Nezko1

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 03:32:13