The reason is the following: in the report visual, you are taking columns from your sales
table (year, month, first day..., etc). PREVIOUSMONTH
works like this - it take first date in the context (from the date column supplied as the first argument) and returns a table of all dates for the previous month. So in theory, this should work.
However, since your visual only contains columns from the sales table, and you most likely have a single direction one to many relationship between your date table and sales, there is no time[date]
in the context. Therefore, PREVIOUSMONTH
does not return anything!
To fix your problem, I would suggest to add year and month columns to you time table and use those in your visual.
Let me know if I got it right.
EDIT
To expand on why there is no time[date]
in the context, I will explain how single direction one-to-many
relationships work.
In those cases there is always a table on the one
side of the relationship (let's call it a filtering table
) and the other table on the many
side of the relationship (let's call it filtered table
).
When you select (through a slicer/filter/cross-highlight) values from the filtering table
, rows in the filtered table
are limited to those matching the selection (the filter context
) in the filtering table
. The same happens when you calculate a measure in a visual (a table for instance). Values that are displayed in individual rows (row context
) from the filtering table
filter rows from the many
side table.
However, it doesn't work the other way round, as it is a single direction
relationship. This would work for bi-direcional relationship
, but that has its own implications as well.
That's why I suggested putting columns from the time
table into the visual, as that will introduce filtering row context
for PREVIOUSMONTH
function to work.
CALCULATE(TOTALMTD(SUM(sales[sales]), time[dateKey]), PREVIOUSMONTH(time[dateKey]))
? This might not be what you are looking for (the month to day sum), but it's difficult to tell without seeing what you're attempting, as everything in DAX is context dependent. – W.B.