首页 > 解决方案 > 在 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]
  
        )

我的问题中模型的一部分

标签: powerbidaxssas-tabular

解决方案


推荐阅读