Use of SAMEPERIODLASTYEAR (or similar DAX functions) together with filters and slicers
This can be more complicated than it seems.
Let´s demonstrate it on this table, showing dates, numbers and categories.
If the syntax is like this, then it somehow works. In visual we can see current values as well as previous year values:
But when you select some category (using filter, slicer etc.), there is something wrong:
Let´s start with a new table (dimension) creation, using the CALENDARAUTO function:
This should be connected with the original table, using relation.
Now change the syntax of measure. ALL function wouldn't be used. SAMEPERIODLASTYEAR will use the date column from time dimension, which will be also used in visual.
- Last Year = CALCULATE(
SUM('Table'[Number of something]),
From now, it works perfectly - no matter how many filters is used.