I think this will work:
Expected Result =
VAR Summary =
SUMMARIZE (
Unique_Manager,
Unique_Manager[Manager],
"Budget_Brand", SUM ( Budget_Brand[BudgetBrand] ),
"Budget_Product", SUM ( Budget_Product[BudgetProduct] )
)
RETURN
SUMX (
Summary,
IF ( ISBLANK ( [Budget_Product] ), [Budget_Brand], [Budget_Product] )
)
This groups by Manager
and calculates a summary table with the sum for BudgetBrand
and BudgetProduct
for each and the iterates through this summary table with SUMX
using the logic specified.
Here's a bit cleaner implementation
Expected Result =
SUMX (
VALUES ( Unique_Manager[Manager] ),
VAR SumBrand = CALCULATE ( SUM ( Budget_Brand[BudgetBrand] ) )
VAR SumProduct = CALCULATE ( SUM ( Budget_Product[BudgetProduct] ) )
RETURN
IF ( ISBLANK ( SumProduct ), SumBrand, SumProduct )
)
I this one, we don't need a calculated table to iterate over. Instead, we iterated over all the distinct values of Manager
in the local filter context and sum BudgetBrand
and BudgetProduct
within that context. Note that I've wrapped the sums in CALCULATE
. This is done to perform the context transition from the row context inside SUMX
(the particular Manager
) to having that Manager
as a filter context on BudgetBrand
and BudgetProduct
. Storing these sums as variables makes for a more readable IF
line and only requres SumProduct
to be computed once instead of twice.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…