Power BI 视觉筛选器不筛选所有其他视觉对象

时间:2021-06-04 19:34:44

标签: powerbi dax powerbi-desktop

我有一个用于填充日期切片器的日期表。日期切片器过滤页面上的所有其他过滤器,但一个除外。它没有过滤的那个与日期表具有一对多的关系。

但是,当我使用表 2 中的数据作为轴(日期和小时)时,它实际上显示整个表中的所有日期/小时,但不会将日期/小时范围限制为父日期表(表一)。关于如何在不使用合并表的情况下实现这一目标的想法(在 DAX 中更可取)?

在 SQL Server 中,我将执行以下操作来实现此输出:

select fc1.calendardatewithtime, totaltable.total
from FiscalCalendarWithTime fc1
cross apply (
select top(1) count(distinct id) total
from ActionDetail ad1
where ad1.upgraded_on=fc1.calendardatewithtime and ad1.status=3
)as totaltable
where exists ( select 1 from dbo.FiscalCalendarTable fc2 where fc2.calendardate=fc1.calendardate and fc2.fiscalweek=1 )
order by fc1.calendardatewithtime asc;

其中 calendardatewithtime 是我将用作轴的带有时间字段的日期,totaltable.total 是我将显示为图表总计的值。

我的日期切片器代码:

SpecialDateDropdown = 
VAR _datetable = FiscalDGCalendar
VAR _today = TODAY()
VAR _yesterday = TODAY()-1
VAR CurrentFiscalWeek = calculate(min(FiscalCalendar[fiscal_week]),filter(FiscalCalendar,format(now(),"mm/dd/yyyy")=format(FiscalCalendar[fiscal_date],"mm/dd/yyyy")))
VAR CurrentFiscalPeriod = calculate(min(FiscalCalendar[fiscal_period]),filter(FiscalCalendar,format(now(),"mm/dd/yyyy")=format(FiscalCalendar[fiscal_date],"mm/dd/yyyy")))
VAR CurrentFiscalQuarter = calculate(min(FiscalCalendar[fiscal_quarter]),filter(FiscalCalendar,format(now(),"mm/dd/yyyy")=format(FiscalCalendar[fiscal_date],"mm/dd/yyyy")))
VAR CurrentFiscalYear = calculate(min(FiscalCalendar[fiscal_year]),filter(FiscalCalendar,format(now(),"mm/dd/yyyy")=format(FiscalCalendar[fiscal_date],"mm/dd/yyyy")))
RETURN UNION(
    ADDCOLUMNS(FILTER(_datetable,[fiscal_date]=_today),"Period","Today","Order",1),
    ADDCOLUMNS(FILTER(_datetable,[fiscal_date]=_yesterday),"Period","Yesterday","Order",2),
    ADDCOLUMNS(FILTER(_datetable,[fiscal_year]=CurrentFiscalYear&&[fiscal_week]=CurrentFiscalWeek),"Period","Current Fiscal Week","Order",3),
    ADDCOLUMNS(FILTER(_datetable,[fiscal_year]=CurrentFiscalYear&&[fiscal_week]=CurrentFiscalWeek-1),"Period","Prior Fiscal Week","Order",4),
    ADDCOLUMNS(FILTER(_datetable,[fiscal_year]=CurrentFiscalYear&&[fiscal_period]=CurrentFiscalPeriod),"Period","Current Fiscal Month","Order",5),
    ADDCOLUMNS(FILTER(_datetable,[fiscal_year]=CurrentFiscalYear&&[fiscal_period]=CurrentFiscalPeriod-1),"Period","Prior Fiscal Month","Order",6),
    ADDCOLUMNS(FILTER(_datetable,[fiscal_year]=CurrentFiscalYear&&[fiscal_quarter]=CurrentFiscalQuarter),"Period","Current Fiscal Quarter","Order",7),
    ADDCOLUMNS(FILTER(_datetable,[fiscal_year]=CurrentFiscalYear),"Period","Current Fiscal Year","Order",8),
    ADDCOLUMNS(_datetable,"Period","Custom Date Range","Order",9)
)

这就是我收集总数的方式,因此我唯一缺少的是如何仅直观地显示特定日期范围:

CALCULATE(
IF(
    ISBLANK(DISTINCTCOUNT(ActionHistoryDetail[id])),0,DISTINCTCOUNT(ActionHistoryDetail[id])
),ActionHistoryDetail[status]=3,USERELATIONSHIP(FiscalCalendar[fiscal_date],fiscalcalendarwithtime[CalendarDate]),USERELATIONSHIP(fiscalcalendarwithtime[CalendarDateWithTime],ActionHistoryDetail[upgraded_on])
)

2 个答案:

答案 0 :(得分:0)

您可以将切片器归为一个系列,因为所有切片器都具有相同的值(如果值相同)。然后你可以将第二个切片器隐藏在第一个切片器后面。

  1. 如您所见,Date Table 并未过滤 DATA TABLE,因为我尚未将它们分组。

Without Grouping

  1. 现在我必须在功能区中查看并选择同步切片器选项,然后转到高级控件并将两个切片器分组为 A

View >> Sync Slicers >> Advanced Options

How to use this

  1. 现在,由于两个切片器都已分组,当我从 Year 切片器中选择 Data Table 时,它也会过滤 DATA TABLE 表。

Ta-da Output

  1. 现在只需隐藏另一个切片器。

如果此答案对您有帮助,请将其标记为答案。谢谢。

答案 1 :(得分:0)

你应该检查你的人际关系。

确保您有一个映射到主表的日期表。