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

Power BI报表:添加动态月份对比参数并取消表格默认筛选

Power BI实现动态月份对比的新增电脑统计解决方案

1. 创建独立的切片器表

直接使用原表tblComputer的YearMonth列做切片器时,会通过模型关系自动筛选所有关联视觉对象,因此需要创建两个无关联的独立表作为切片器数据源:

创建目标月份切片器表(用于选择要统计的月份):

Slicer_TargetMonth = DISTINCT('tblComputer'[YearMonth])

创建基准月份切片器表(用于选择对比的月份):

Slicer_BaseMonth = DISTINCT('tblComputer'[YearMonth])

注意:不要让这两个新表和tblComputer建立任何关系,保持独立状态。

2. 修改度量值支持动态月份选择

替换原固定日期的度量值,用SELECTEDVALUE函数获取切片器选中值,实现动态计算:

Count of New Computers = 
// 获取切片器选中的目标月份与基准月份
VAR TargetMonth = SELECTEDVALUE(Slicer_TargetMonth[YearMonth])
VAR BaseMonth = SELECTEDVALUE(Slicer_BaseMonth[YearMonth])
// 提取目标月份的所有电脑列表
VAR TargetComputers = CALCULATETABLE(VALUES('tblComputer'[Computer]), 'tblComputer'[YearMonth] = TargetMonth)
// 提取基准月份的所有电脑列表
VAR BaseComputers = CALCULATETABLE(VALUES('tblComputer'[Computer]), 'tblComputer'[YearMonth] = BaseMonth)
// 计算目标月份存在、但基准月份未出现的新增电脑数量
RETURN
CALCULATE(
    DISTINCTCOUNT('tblComputer'[Computer]),
    'tblComputer'[YearMonth] = TargetMonth,
    NOT('tblComputer'[Computer] IN BaseComputers)
)

3. 设置切片器并验证效果

  • 向报表添加两个切片器视觉对象,分别选择Slicer_TargetMonth[YearMonth]和Slicer_BaseMonth[YearMonth]作为字段
  • 添加卡片或表格视觉对象,放入修改后的Count of New Computers度量值
  • 此时选择两个切片器的月份,只会将选中值传递给度量值计算,不会自动筛选原表数据,实现动态对比需求

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 12:33:32