问题描述
我是Power BI的新手,我试图了解一些功能。
我尝试了两种方法:
1-在AVERAGEX函数中具有计算的显式 平均X = AVERAGEX(产品, 产品[金额] *产品[折扣])
2-我尝试通过首先计算度量中的Products [Amount] * Products [discount]来简化上述过程,然后在AVERAGEX中使用它 平均= AVERAGEX(产品, [总结])
但是,我在表的最后一行得到2个不同的值
解决方法
问题是def example[T](): Unit = {
T match {
case if T extends MyParentClass => ...
case if T extends MyOtherParentClass => ...
case if T extends MyOtherTrait => ...
case _ => default case ...
}
对表中的重复行进行了迭代。
AVERAGEX
将为AVERAGEX(Products,[Sumx])
的每一行评估一次[Sumx]
,每次具有与迭代所访问的行相对应的行上下文。
将同时访问Products
行的第一和第二副本;并将其设置为迭代步骤的当前行上下文。
在每个迭代步骤中,{("Red",50,TRUE(),2)}
会将行上下文转换为过滤器上下文(由于应用了度量的隐式上下文转换),并将获得过滤器上下文[Sumx]
。此过滤器上下文匹配("Red",2)
的两行,因此内部Products
将迭代两行。
最终结果是SUMX(Products,Products[Amount]*Products[Discount])
计算出以下错误值:
AVERAGEX(Products,[Sumx])
(
2000*2
+(50*2+50*2) //Both `{("Red",2)}` rows included in filter context of SUMX
+(50*2+50*2) //Both `{("Red",2)}` rows included in filter context of SUMX again.
)
/3 //3 rows in Products (when Color="Red")
不会将上下文转换应用于行上下文,并且不会在此新的筛选器上下文中迭代行,因此AVERAGEX(Products,Products[Amount]*Products[Discount])
会为{{1}的当前迭代行求值为正确的值}。