Forum Discussion
Conditional measure
Hi KamilRetkiewicz,
I think the issue is that when you are on the "% of Cash Invested" row, the current filter context is still on that category. So you need to remove that filter and then calculate the values from the other two rows.
I'd try this:
AVG_CASH_PERCENT_BUD =
VAR TotalAverageCash =
CALCULATE(
[AVG_CASH_BUD],
REMOVEFILTERS('AVG_CASH_ACT'[CATEGORY]),
'AVG_CASH_ACT'[CATEGORY] = "Total Average Cash"
)
VAR CashInvested =
CALCULATE(
[AVG_CASH_BUD],
REMOVEFILTERS('AVG_CASH_ACT'[CATEGORY]),
'AVG_CASH_ACT'[CATEGORY] = "Cash Invested"
)
RETURN
IF(
SELECTEDVALUE('AVG_CASH_ACT'[CATEGORY]) = "% of Cash Invested",
DIVIDE(CashInvested, TotalAverageCash),
[AVG_CASH_BUD]
)
So, for example, if:
Total Average Cash = 100
Cash Invested = 73
the "% of Cash Invested" row will return 73%.
I'd also avoid FORMAT() in the measure if possible. FORMAT converts the result to text, which can cause problems later if you want to use the measure in other calculations or conditional formatting.
Instead, keep the measure numeric and set its format to Percentage from the Measure tools in Power BI.