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

_add_months配置疑问:上月全月交易数据筛选仅显示首日数据

问题分析与解决办法

为什么单独用_first_of_month(_add_months(current_date, -1))只显示上月第一天数据?

这个表达式本身的作用是返回上月的第一天日期,比如当前是8月,它就返回2023-07-01。你用它作为筛选条件,相当于让“车辆批发日期”等于这个固定日期,自然只会匹配到7月1日的交易数据,而不是整个月份的范围。

你之前尝试的Between表达式存在的问题

  1. 第一个表达式:between (_add_days(_first_of_month(_add_months(current_date, -1))) and (_first_of_month(current_date)))

    • _add_days函数缺少第二个参数(要添加的天数),属于语法错误,导致筛选器无法正确解析范围。
    • 即使修正语法,用_first_of_month(current_date)作为结束值,实际筛选的是上月第一天到当月第一天,可能会错误包含当月零点的交易数据,逻辑不准确。
  2. 第二个表达式:between _first_of_month (_add_months (current_date,-1) and _last_of_month (_add_months (current_date)

    • 括号严重不匹配:_first_of_month后面的括号没闭合,_last_of_month里的_add_months(current_date)也没指定偏移-1(应该是_add_months(current_date, -1)),语法错误直接导致筛选逻辑失效。

正确的筛选表达式写法

要获取上月完整的交易数据,需要明确筛选范围是上月第一天到上月最后一天,推荐两种写法:

写法一:使用Between

between _first_of_month(_add_months(current_date, -1)) and _last_of_month(_add_months(current_date, -1))

写法二:使用>=和<=(更直观)

车辆批发日期 >= _first_of_month(_add_months(current_date, -1)) AND 车辆批发日期 <= _last_of_month(_add_months(current_date, -1))

额外注意点

如果你的“车辆批发日期”是带时间戳的字段(比如包含时分秒),部分BI工具的_last_of_month函数可能只返回上月最后一天的00:00:00,这会漏掉当天非零点的交易数据。这种情况可以把结束值改成当月第一天减去1天(自动包含到上月最后一天的23:59:59):

车辆批发日期 >= _first_of_month(_add_months(current_date, -1)) AND 车辆批发日期 < _first_of_month(current_date)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 22:52:14