PowerBI累计求和性能优化
已经存在基础度量值Sales Amount
Sales Amount =
SUMX ( Sales, Sales[Quantity] * Sales[Net Price] )
Cumulated Sales =
VAR CurrentProductSales = [Sales Amount]
VAR BetterProducts =
FILTER (
ALL('Product'),
[Sales Amount] >= CurrentProductSales
)
VAR Result =
CALCULATE(
[Sales Amount],
BetterProducts
)
RETURN
Result
-
先对产品表进行聚合,算出每个商品的销售额
-
再对聚合后的表进行移动累计计算
Cumulated Sales 2 =
VAR ProductsOfAmt =
ADDCOLUMNS (
ALLSELECTED ( 'Product'[Product Name] ),
[Sales Amount]
)
VAR CurrentOfferAmount = [Sales Amount]
VAR BetterProducts =
FILTER (
ProductsOfAmt,
>= CurrentOfferAmount
)
VAR Result = SUMX( BetterProducts, [@Amt])
RETURN
Result
本篇文章来源于微信公众号: PowerBI木小桼