我正在尝试创建一个报告,该报告将允许我的用户基于列和日期的总和进行选择。因此,我创建了一个表,一列,值是1到20。还有一个日期选择,今天加上14天。在我要求给我所有停电4次以上的设备或Date(2019,07,17)之前,它在20秒内加载了我的视觉效果。现在,我正在使用selectedvalue(),它花费了我9分钟的视觉时间和54秒的加载时间。有什么问题吗?
这需要10分钟
Repeat Devices Outage Count =
var numberSelect = SELECTEDVALUE(Numbers[Numbers])
VAR datesSelection = SelectedValue(Date Selection[DateWoTime])
VAR devicesTotal =
CALCULATETABLE (
VALUES ( Outages[Feeder_Device] ),
ALLSELECTED ( Outages ),
Outages[DATE] >= datesSelection,
VALUES ( Outages[Feeder_Device] )
)
var caseTotal = CALCULATE (
COUNT ( Outages[CASE_ID] ),
ALLSELECTED ( Outages ),
Outages[Feeder_Device] IN devicesTotal)
VAR devices =
CALCULATETABLE (
VALUES ( Outages[Feeder_Device] ),
ALLSELECTED ( Outages ),
Outages[DATE] >= datesSelection
)
RETURN
SWITCH(TRUE(),
caseTotal >= numberSelect,
CALCULATE (
COUNT ( Outages[DEVICE_ID] ),
FILTER ( Outages, Outages[Feeder_Device] IN devices )
),
BLANK()
)
这需要20秒或更短的时间。
Repeat Devices Outage Count =
var numberSelect = 4
VAR datesSelection = Date(2019,07,17)
VAR devicesTotal =
CALCULATETABLE (
VALUES ( Outages[Feeder_Device] ),
ALLSELECTED ( Outages ),
Outages[DATE] >= datesSelection,
VALUES ( Outages[Feeder_Device] )
)
var caseTotal = CALCULATE (
COUNT ( Outages[CASE_ID] ),
ALLSELECTED ( Outages ),
Outages[Feeder_Device] IN devicesTotal)
VAR devices =
CALCULATETABLE (
VALUES ( Outages[Feeder_Device] ),
ALLSELECTED ( Outages ),
Outages[DATE] >= datesSelection
)
RETURN
SWITCH(TRUE(),
caseTotal >= numberSelect,
CALCULATE (
COUNT ( Outages[DEVICE_ID] ),
FILTER ( Outages, Outages[Feeder_Device] IN devices )
),
BLANK()
)
为什么selectedvalue()会使我的报告减速这么快?
答案 0 :(得分:0)
除非您使用了DAX STUDIO之类的方法来衡量小节中的每个元素,否则我都不认为SELECTEDVALUE()
是元凶。我将从消除不必要的FILTER
调用开始,因为这些调用实际上是在每次执行时在内存中创建整个表。试试这个:
Repeat Devices Outage Count =
VAR numberSelect =
SELECTEDVALUE ( Numbers[Numbers] )
VAR datesSelection =
SELECTEDVALUE ( 'Date Selection'[DateWoTime] )
VAR devicesTotal =
CALCULATETABLE (
VALUES ( Outages[Feeder_Device] ),
ALLSELECTED ( Outages ),
Outages[DATE] >= datesSelection,
VALUES ( Outages[Feeder_Device] )
)
VAR caseTotal =
CALCULATE (
COUNT ( Outages[CASE_ID] ),
ALLSELECTED ( Outages ),
Outages[Feeder_Device] IN devicesTotal
)
VAR devices =
CALCULATETABLE (
VALUES ( Outages[Feeder_Device] ),
ALLSELECTED ( Outages ),
Outages[DATE] >= datesSelection
)
RETURN
SWITCH (
TRUE (),
caseTotal >= numberSelect,
CALCULATE ( COUNT ( Outages[DEVICE_ID] )
, Outages[Feeder_Device] IN devices ),
BLANK ()
)
或者这个(相当于可读性更强):
Repeat Devices Outage Count =
VAR numberSelect =
SELECTEDVALUE ( Numbers[Numbers] )
VAR datesSelection =
SELECTEDVALUE ( 'Date Selection'[DateWoTime] )
VAR devicesTotal =
CALCULATETABLE (
VALUES ( Outages[Feeder_Device] ),
ALLSELECTED ( Outages ),
Outages[DATE] >= datesSelection,
VALUES ( Outages[Feeder_Device] )
)
VAR caseTotal =
CALCULATE (
COUNT ( Outages[CASE_ID] ),
ALLSELECTED ( Outages ),
Outages[Feeder_Device]
IN devicesTotal
)
VAR devices =
CALCULATETABLE (
VALUES ( Outages[Feeder_Device] ),
ALLSELECTED ( Outages ),
Outages[DATE] >= datesSelection
)
RETURN
SWITCH (
TRUE (),
caseTotal >= numberSelect, CALCULATE (
COUNT ( Outages[DEVICE_ID] ),
FILTER (
ALL ( Outages[Feeder_Device] ),
Outages[Feeder_Device]
IN devices
)
),
BLANK ()
)
本文:FILTER ARGUMENTS IN CALCULATE克服了在整个表上使用FILTER
的危险。
答案 1 :(得分:0)
因此,我已经调整了代码,这可以正常工作。这是我能想到的最接近“具有”功能的东西。现在我的报告恢复正常。我想这不是选定的值,因为“ Outages [DATE]> = dateSelection”的工作原理应该是这样。因此,我假设它必须使用“ IF”和“ Switch”功能。
Repeat Devices Outage Count =
var numberSelect = SELECTEDVALUE(Numbers[Numbers])
VAR datesSelection = SELECTEDVALUE('Date Selection'[Date])
VAR devicesTotal =
CALCULATETABLE (
VALUES ( Outages[Feeder_Device] ),
ALLSELECTED ( Outages ),
Outages[DATE] >= datesSelection,
VALUES ( Outages[Feeder_Device] )
)
var caseTotal = CALCULATE (
COUNT ( Outages[CASE_ID] ),
ALLSELECTED ( Outages ),
Outages[Feeder_Device] IN devicesTotal)
VAR devices =
CALCULATETABLE (
VALUES ( Outages[Feeder_Device] ),
ALLSELECTED ( Outages ),
Outages[DATE] >= datesSelection
)
RETURN
CALCULATE (
COUNT ( Outages[DEVICE_ID] ),
FILTER ( Outages, Outages[Feeder_Device] IN devices ),
FILTER(Outages, caseTotal >= numberSelect)
)