I have a table of orders, with contains seller id, order date, amount and country (among other fields). I need a measure that calculates the sum of amounts for the country and year in context. So, for example:
This measure, of course, will be affected by any 'year' or 'country' filter active in the dashboard
I will use this measure later for many purposes. For example, filter in the dashboard only the countries that, for the year selected in context, have ordered more than certain amount
Can you help me, please?
Have a look at the ISINSCOPE
function.
Your measure could look like:
Your Measure =
var thisYear = YEAR(MAX(YourTable[Date]))
return SWITCH(TRUE(),
ISINSCOPE(YourTable[Seller Id]) && ISINSCOPE(YourTable[Date]),
CALCULATE( SUM(YourTable[Amount]), REMOVEFILTERS(YourTable[Seller Id]), REMOVEFILTERS(YourTable[Date]), YourTable[Year] = thisYear),
ISINSCOPE(YourTable[Seller Id]),
CALCULATE( SUM(YourTable[Amount]), REMOVEFILTERS(YourTable[Seller Id])),
ISINSCOPE(YourTable[Date]),
CALCULATE( SUM(YourTable[Amount]), REMOVEFILTERS(YourTable[Date]), YourTable[Year] = thisYear),
// else
SUM(YourTable[Amount])
)