True/False expression that is used as a table filter expression. This is not allowed

I am trying to add this code:

CALCULATE(
SUM(‘ZTBR’[Amount in USD]),
‘ZTBR’[Classification] IN {
“Below MOP”,
“Interest expense”,
“Profit before Brambles allocations Total”,
“Profit before Brambles allocations”,

		"Interco dividends",
		"Interest expense"
		
		}

To:

Totals by Account Description & Code3 =
VAR SelectedCashFlowDescription = SELECTEDVALUE(‘CashflowDiscriptions’[Description], “None”)
VAR _TotalNetDept = CALCULATE([Net debt increase/decrease], ALL(CashflowDiscriptions))
VAR _TotalNetTaxPaid = CALCULATE([Net Tax Paid], ALL(CashflowDiscriptions))
VAR _TotalIntercoCashFlows = CALCULATE([IntercoCashFlows], ALL(CashflowDiscriptions))
VAR _TotalOtherCashFlowItems = CALCULATE([Other cash flow items], ALL(CashflowDiscriptions))
VAR _TotalInterestPaid = CALCULATE([Interest paid], ALL(CashflowDiscriptions))
VAR _TotalInterestExpenseNotImpactingCashFlow = CALCULATE([Interest expense not impacting cash flow], ALL(CashflowDiscriptions))
VAR _TotalCashFlowFromOpsStatutory = CALCULATE([Cash flow from ops - statutory], ALL(CashflowDiscriptions))
VAR _TotalOtherCashFlowfromTradingAdjustments = CALCULATE([Other cash flow from trading adjustments], ALL(CashflowDiscriptions))
VAR _TotalDisposalsImpairmentofFixedAssets = CALCULATE([Disposals & impairment of fixed assets], ALL(CashflowDiscriptions))
VAR _TotalWorkingCapitalMvtsExclProvisions = CALCULATE([Working capital mvts excl. provisions], ALL(CashflowDiscriptions))
VAR _TotalOtherPPEAcquired = CALCULATE([Other PP&E acquired], ALL(CashflowDiscriptions))
VAR _TotalPurchasesOfPPE = CALCULATE([Purchases of PP&E], ALL(CashflowDiscriptions))
VAR _TotalWorkingCapitalMvtsInclProvisions = CALCULATE([Working capital mvts incl. provisions], ALL(CashflowDiscriptions))
VAR _TotalProceedsOtherPPEDisposals = CALCULATE([Proceeds other PP&E disposals], ALL(CashflowDiscriptions))
VAR _TotalProceedsPoolingDisposals = CALCULATE([Proceeds pooling disposals], ALL(CashflowDiscriptions))
VAR _TotalProceedsFromDisposals = CALCULATE([Proceeds from disposals], ALL(CashflowDiscriptions))
VAR _TotalPoolingEquipmentAcquired = CALCULATE([Pooling equipment acquired], ALL(CashflowDiscriptions))
VAR _TotalDisposalProceedsCashFlowAdjustments = CALCULATE([Disposal proceeds cash flow adjustments], ALL(CashflowDiscriptions))
VAR _TotalCapitalExpenditure = CALCULATE([Capital expenditure], ALL(CashflowDiscriptions))
VAR _TotalWorkingCapitalBudgetFlex = CALCULATE([Working capital mvts incl. provisions], ALL(CashflowDiscriptions))
VAR _TotalCashFlowfromTrading = CALCULATE([Cash flow from trading], ALL(CashflowDiscriptions))
VAR _TotalCashFlowFromOpsManagement = CALCULATE([Cash flow from ops - management], ALL(CashflowDiscriptions))
VAR _TotalCashFlowImbalance = CALCULATE([Cash flow imbalance], ALL(CashflowDiscriptions))
VAR _LeasesPrincipalRepaid = CALCULATE(SUM(Bracs[Metric Value ($)]), Bracs[Metric] = “Leases principal repaid”)

RETURN
SWITCH(
TRUE(),
SelectedCashFlowDescription = “Interco capital returned”, 678,
SelectedCashFlowDescription = “Net debt increase/(decrease)”, _TotalNetDept,
SelectedCashFlowDescription = “Cash flow imbalance”, _TotalCashFlowImbalance,
SelectedCashFlowDescription = “Cash flow from ops - management”,_TotalCashFlowFromOpsManagement,
SelectedCashFlowDescription = “Working capital mvts incl. provisions”, _TotalWorkingCapitalBudgetFlex,
SelectedCashFlowDescription = "Proceeds from disposals ", _TotalProceedsFromDisposals,
SelectedCashFlowDescription = “Proceeds other PP&E disposals”, _TotalProceedsOtherPPEDisposals,
SelectedCashFlowDescription = “Proceeds pooling disposals”, _TotalProceedsPoolingDisposals,
SelectedCashFlowDescription = “Capital expenditure”, _TotalCapitalExpenditure,
SelectedCashFlowDescription = “Net tax paid”, _TotalNetTaxPaid,
SelectedCashFlowDescription = “IntercoCashFlows”, _TotalIntercoCashFlows,
SelectedCashFlowDescription = “Leases principal repaid”, _LeasesPrincipalRepaid,
SelectedCashFlowDescription = “OtherCashFlowItems”, _TotalOtherCashFlowItems,
SelectedCashFlowDescription = “Interestpaid”, _TotalInterestPaid,
SelectedCashFlowDescription = “Interest expense not impacting cash flow”, _TotalInterestExpenseNotImpactingCashFlow,
SelectedCashFlowDescription = “CashFlowFromOps - Statutory”, _TotalCashFlowFromOpsStatutory,
SelectedCashFlowDescription = “Other cash flow from trading adjustments”, _TotalOtherCashFlowfromTradingAdjustments,
SelectedCashFlowDescription = “Disposals & impairment of fixed assets”, _TotalDisposalsImpairmentofFixedAssets,
SelectedCashFlowDescription = “Working capital mvts excl. provisions”, _TotalWorkingCapitalMvtsExclProvisions,
SelectedCashFlowDescription = “Working capital mvts incl. provisions”, _TotalWorkingCapitalMvtsInclProvisions,
SelectedCashFlowDescription = “Cash flow from trading”, _TotalCashFlowfromTrading,
SelectedCashFlowDescription = “Pooling equipment acquired”, _TotalPoolingEquipmentAcquired,
SelectedCashFlowDescription = “Other PP&E acquired”, _TotalOtherPPEAcquired,
SelectedCashFlowDescription = “Purchases of PP&E”, _TotalPurchasesOfPPE,
SelectedCashFlowDescription = “Working capital mvts incl. provisions”, _TotalWorkingCapitalBudgetFlex,
SelectedCashFlowDescription = “FX on foreign currency denominated debt”,
CALCULATE(
SUM(‘ZTBR’[Amount in USD]),
‘ZTBR’[Roll_Up_Function] = “FX on foreign currency denominated debt”
),
// Default calculation if no specific match is found
CALCULATE(
SUM(‘ZTBR’[Amount in USD]),
‘ZTBR’[Roll_Up_Function] IN {
“Cash share issues by Brambles Limited”,
“Cost sharing payments to Brambles Limited”,
“Cash paid for share buyback”,
“Equity raised cash flow adjustment”,
“Cash flow from ops - management”,
“Cash flow from trading”,
“Change in capex creditors”,
“Profit before Brambles allocations Total”,
“Depreciation and amortisation”,
“IPEP expense”,
“Disposals & impairment of fixed assets”,
“Profit on disposal of pooling equipment”,
“Scrapped pooling equipment”,
“Impairment or valuation adjustment of pooling equipment”,
“Disposals or valuation adjustments of other fixed assets”,
“Other cash flow from trading adjustments”,
“Other current debtors”,
“Share-based payments expense”,
“Working capital mvts excl. provisions”,
“Debtor movements”,
“Creditor movements”,
“Inventory movements”,
“Prepayment movements”,
“Change in loss compensation balances”,
“Change in capex creditors”,
“Provision movements”,
“Change in capex creditors”,
“FX on foreign currency denominated debt Total”,
“Brambles allocations not in mgt cash flow”,
“Interco interest and guarantee fees”,
“Interco cash flows”,
“Interco royalties”,
“Interco cash flow adjustments”,
“Internal restructuring”,
“Interco dividends Total”,
“Change in interco balances”,
“Change in interco recharge clearing”,
“FX on interco debt”,
“Interco capital returned”,
“Interco cash flow adjustments”,
“Interest expense Total”,
“Interest revenue”,
“Interest paid”,
“Interest received”,
“Cash flow from ops - statutory adjustment”,
“Lease interest”,
“Statutory reallocations”
}
) + CALCULATE(
SUM(Bracs[Metric Value ($)]),
Bracs[Metric] IN {
“Entity acquisitions and disposals”,
“Entity acquisitions”,
“Total purchase price of entities acquired”,
“Purchase price of entities acquired”,
“Cash price of entities acquired”,
“Non-cash consideration in purchase price”,
“Costs directly incurred on entity acquisitions”,
“Deferred settlement of entity acquisitions”,
“Deferred settlements now paid”,
“Non-cash consideration for entity acquisitions”,
“Net cash held by entity at date of acquisition”,
“Entity acquisition cash flow adjustments”,
“Proceeds from entity disposals”,
“Net price of entities disposed”,
“Agreed sale price of entities disposed”,
“Cash price of entities disposed”,
“Non-cash consideration in agreed sale price”,
“Costs directly incurred on entity disposals”,
“Provisions raised on entity disposals”,
“Net change disposal provisions and accruals”,
“Deferred settlement of entity disposals”,
“Deferred settlements now received”,
“Non-cash consideration for entity disposals”,
“Net cash held by entity at date of disposal”,
“Entity disposal cash flow tax adjustments”,
“Entity disposal cash flow other adjustments”,
“Pension plan adjustment”,
“Pension plan adjustment”,
“Working capital - budget flex”,
“Pooling equipment additions”,
“Pooling equipment replacements”,
“Pooling equipment internal transfers”,
“Other PP&E additions”,
“Other PP&E replacements”,
“Other PP&E internal transfers”,
“Joint venture loans”,
“WDV pooling equip. disposals & write-offs”,
“Gain pooling equip. disposals & write-offs”,
“WDV other PP&E disposals”,
“Profit other PP&E disposals”,
“Discount unwind on long term provisions”,
“Tax paid”,
“Joint venture loans”,
“Tax refunded”,
“Working capital - budget flex”,
“Fiscal unity tax transfers”,
“Other cash flow items”,
“FX adjustments to cash flow”,
“Change in cash net of overdraft”
}
)
)

Im geting the error below:

“A function ‘CALCULATE’ has been used in a True/False expression that is used as a table filter expression. This is not allowed.”

@Yrstruly,

The error you’re getting suggests a misunderstanding of how the CALCULATE function can be used within a logical expression.

The CALCULATE function is designed to modify the filter context of an expression and cannot directly be used as part of a condition in a logical test like SWITCH that expects a boolean result. Instead, CALCULATE is used to compute an aggregate value with an altered filter context. The issue arises from trying to embed CALCULATE within the logical test of the SWITCH function, which is not permitted as DAX expects a boolean expression to determine the execution path.

Refactor such that CALCULATE is not used directly in a way that DAX interprets as a condition for a logical test. Instead, calculations or filters that need to be applied should be resolved outside the logical test (i.e., outside the SWITCH function) or integrated into the return values of the SWITCH function properly.

You need to ensure that CALCULATE is used to define variables or directly in the return expression rather than as part of the logical condition.

If you haven’t already, you may want to review some documentation and elaborations of those materials especially those focusing on CALCULATE and the proper use of logical expressions. Microsoft’s official documentation provides a comprehensive reference for DAX, explaining the syntax and usage of functions, including how logical expressions can be effectively combined with functions like CALCULATE. The DAX Guide is an excellent resource for in-depth explanations and examples. Additionally, ‘The Definitive Guide to DAX’ by Alberto Ferrari and Marco Russo provides thorough insights into both the basics and advanced aspects of DAX, including the nuances of logical expressions and context management.