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

如何在Power BI中计算截至当前月份的累计值并隐藏后续月份?

Power BI累计求和并隐藏后续无数据月份

原始数据

月份数值
2023年1月2
2023年2月4
2023年3月0

需求

计算截至当前月份的累计求和值,仅显示到最后一个有非零数值的月份,后续无数据(数值为0)的月份不显示。预期结果:

2023年1月 2
2023年2月 6
不应显示3月

现有问题

使用以下DAX公式时,3月会被计算出累计值6并显示:

Actuals running total in Month 2: = 
CALCULATE(
    SUM('BI_ClientAdoptionReport'[Actuals]),
    FILTER(
        ALL('BI_ClientAdoptionReport'[Month]),
        ISONORAFTER('BI_ClientAdoptionReport'[Month], MAX('BI_ClientAdoptionReport'[Month]), DESC)
    )
)

解决方案

修正后的DAX公式如下:

累计求和 = 
VAR LastValidMonth = 
    CALCULATE(
        MAX('BI_ClientAdoptionReport'[Month]),
        'BI_ClientAdoptionReport'[Actuals] <> 0
    )
RETURN
IF(
    MAX('BI_ClientAdoptionReport'[Month]) > LastValidMonth,
    BLANK(),
    CALCULATE(
        SUM('BI_ClientAdoptionReport'[Actuals]),
        FILTER(
            ALL('BI_ClientAdoptionReport'[Month]),
            'BI_ClientAdoptionReport'[Month] <= MAX('BI_ClientAdoptionReport'[Month])
        )
    )
)

逻辑说明

  1. LastValidMonth变量:定位到最后一个存在非零实际值的月份,本例中为2023年2月。
  2. 空值判断:如果当前行的月份晚于这个有效月份,返回空值(BLANK()),Power BI默认会隐藏空值对应的行。
  3. 累计计算:对于有效范围内的月份,计算从起始到当前月份的累计求和。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 12:55:59