如何从SUMX中删除行上下文,以使其包含正在迭代的表变量的所有记录?
我尝试了此操作,但没有效果(用FILTER包裹表以说出“所有期间日期值”)–最终仍不是我想要的:
SUMX(FILTER(varCoverageTableYTD
, ALL('Equipment Cost on Rent With Branch'[PeriodDate])
, DIVIDE([Days on Rent with Branch], [Billable Days with Branch])
*
DIVIDE([Billable Days with Branch], [Total Days with Branch])
*
'Equipment Cost on Rent With Branch'[EquipmentCostForCORMeasure_CCUR]
))
我以前采用了不同的方法。我曾经认为我的问题是过滤器上下文,所以将其删除。这样做之后,我假设它是继承行上下文的SUMX迭代器。
这里是完整的度量定义。我相信我已经将问题隔离到SUMX(正如我已经描述过的)。但是,显示整个定义的代码可能会有好处:
// Convert the user selected period into Begin and End Dates
VAR varLastDateYTD = LASTDATE(DATESYTD('Calendar'[Calendar Date]))
VAR varFirstDateYTD = DATE(YEAR(varLastDateYTD), 1, 1)
// Remove the filter context which is coming from the user selection
VAR varCoverageTableAllDates = CALCULATETABLE('Equipment Cost on Rent With Branch'
, ALL('Equipment Cost on Rent With Branch'[PeriodDate])
)
// Filter the table to the calculated Begin and End Dates
VAR varCoverageTableYTD = FILTER(varCoverageTableAllDates
, 'Equipment Cost on Rent With Branch'[PeriodDate] <= varLastDateYTD
&& 'Equipment Cost on Rent With Branch'[PeriodDate] >= varFirstDateYTD
)
// Iterate over the new table, calculating on a per row basis.
// Does SUMX get a row context from the user selection?
// My result is limited to the user selected period.
RETURN SUMX(varCoverageTableYTD,
, DIVIDE([Days on Rent with Branch], [Billable Days with Branch])
*
DIVIDE([Billable Days with Branch], [Total Days with Branch])
*
'Equipment Cost on Rent With Branch'[EquipmentCostForCORMeasure_CCUR]
)