powerbi - 在 SSAS 表格的 DAX 度量中使用 SUMX 时,如何删除来自用户选择的行上下文?
问题描述
如何从 SUMX 中删除行上下文,以便它包含它正在迭代的表变量的所有记录?
我试过这个,但它没有效果(用过滤器包装表格说“所有期间日期值”)——这仍然不是我最终想要的:
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]
)
解决方案
推荐阅读
- sql-server - 在 TSQL 中生成等效的脚本
- c++ - 联合声明的两种不同语法如何给我不同的大小?
- enums - 在 OpenAPI (Swagger) 中重用枚举的子集
- maven - 可以从命令行将 maven updatePolicy 设置为从不吗?
- python - 如何将 60 分钟的数据点划分为 15 分钟?
- google-apps-script - 优化 OnEdit() 脚本
- android - Cordova 应用程序仅在分屏视图/多个应用程序视图中显示
- mysql - 如何使用游标根据另一列更新某些列?
- c - 如何将 char** 转换为 Vec
生锈 - ruby-on-rails - 多个字段 sort_by 组合的 reverse 和 not