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

PowerBI DAX:创建仅标记当前报告月为True的IsCurrentMonth列

解决DAX计算列仅标记当前报告月的问题

关键逻辑梳理

要实现仅让当前报告月显示True,核心是先准确计算出当前的报告月:

  • 当系统日期(TODAY())落在当月第7个工作日及之后时,报告月切换为上个月
  • 系统日期在当月第7个工作日之前时,报告月仍为当月

完整DAX计算列公式

假设你的报告月份表中,存储月份的列是[ReportMonth](格式为当月第一天,比如2024-01-01代表2024年1月),直接用下面的公式创建IsCurrentMonth计算列:

IsCurrentMonth = 
VAR CurrentDate = TODAY()
VAR CurrentMonthFirstDay = DATE(YEAR(CurrentDate), MONTH(CurrentDate), 1)
VAR Month7thWorkday = WORKDAY(CurrentMonthFirstDay, 7)
// 若公司有自定义节假日,修改为 WORKDAY(CurrentMonthFirstDay, 7, '节假日表'[日期])
VAR CurrentReportMonth = 
    IF(
        CurrentDate >= Month7thWorkday,
        DATE(YEAR(CurrentDate), MONTH(CurrentDate)-1, 1),
        CurrentMonthFirstDay
    )
RETURN
    [ReportMonth] = CurrentReportMonth

公式细节解释

  • CurrentDate:获取当前系统日期
  • CurrentMonthFirstDay:算出当前月份的第一天
  • Month7thWorkday:计算当月第7个工作日(WORKDAY自动跳过周六周日,有节假日的话加上对应节假日列即可)
  • CurrentReportMonth:根据当前日期是否过了当月第7个工作日,确定当前报告月是当月还是上个月
  • 最后判断当前行的[ReportMonth]是否等于计算出的CurrentReportMonth,返回True或False

现有公式问题排查

你的公式会标记所有历史月份为True,大概率是用了[ReportMonth] <= CurrentReportMonth这类范围判断,改成严格的相等判断[ReportMonth] = CurrentReportMonth就能解决问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 02:52:21