Can someone figure out what is wrong with my code?
Purpose of the code:
If the column Brand is filtered and SKU is not --> value sales of 2022 of the whole brand with all SKUs
If the column SKU is filtered --> value sales of 2022 of a specific SKU
If no filters --> value sales of 2022 of all the brands & all the SKUs
Total Sales 2022 III =
VAR SelectedBrand = SELECTEDVALUE('DATA'[Brand])
VAR SelectedSKU = SELECTEDVALUE('DATA'[SKU])
RETURN
CALCULATE(
IF(
ISFILTERED('DATA'[Brand]) && ISFILTERED('DATA'[SKU]),
SUM('DATA'[Sales (€)])),
IF(
ISFILTERED('DATA'[Brand]),
CALCULATE(
SUM('DATA'[Sales (€)])),
FILTER(
ALL('DATA'),
YEAR('DATA'[Time period]) = 2022 &&
'DATA'[Brand] = SelectedBrand
)
),
IF(
ISFILTERED('DATA'[SKU]),
CALCULATE(
SUM('DATA'[Sales (€)])),
FILTER(
ALL('DATA'),
YEAR('DATA'[Time period]) = 2022 &&
'DATA'[SKU] = SelectedSKU
)
),
CALCULATE(
SUM(DATA[Sales (€)])),
FILTER(
ALL('DATA'),
YEAR('DATA'[Time period]) = 2022
)
)