我遇到一种情况,在99%的零售商品列表中,计算销售成本很简单:
COGS:=
SUM([Units Sold]) * [Unit Purch Cost]
但是,我有一些在这段时间内没有购买但被出售的物品。因此,我想使用该子类别中某商品的平均费用:
Avg Special Cost :=
CALCULATE (
SUM ( [Extended Cost] ) / SUM ( [Purchase Qty] ),
Products[SubCategory] = "Special"
)
现在,我正在尝试编写可更新标准COGS度量的度量:
COGS :=
CALCULATE (
SUM ( [Units Sold] ) * [Unit Purch Cost],
Products[SubCategory] <> "Special"
)
+ CALCULATE (
SUM ( [Units Sold] ) * [Avg Special Cost],
Products[SubCategory] = "Special"
)
这似乎在汇总中起作用,但是我似乎无法在Power BI矩阵表的项目级别上应用它。有可能修改的想法吗?
答案 0 :(得分:1)
尝试一下:
COGS :=
VAR AverageValue =
CALCULATE ( DIVIDE ( SUM ( [Extended Cost] ), SUM ( [Purchase Qty] ) ) )
RETURN
CALCULATE (
SUMX ( 'Products', 'Products'[Units Sold] * 'Products'[Unit Puch Cost] ),
Products[SubCategory] <> "Special"
)
+ CALCULATE (
SUMX ( 'Products', [Unit Sold] * AverageValue ),
'Products'[SubCategory] = "Special"
)
我不确定我的表是否正确:),但我认为这至少可以使您朝正确的方向前进。