Forum Discussion
Oros
Post Prodigy
2 years agoLast X MONTHS based on selected MONTH
Hello, I have a date table and a sales table. What would be the correct measure if I would like to show the last X months based on the selected month. For example, if I need to show the last 6 ...
- 2 years ago
Hi,
Try this:
SalesLastXMonths =
VAR SelectedMonth = MAX('Date'[Month]) -- Get the selected month
VAR SelectedYear = MAX('Date'[Year]) -- Get the selected year
VAR StartDate =
EDATE(DATE(SelectedYear, SelectedMonth, 1),
-6 )-- Adjust this value to show the last X months (e.g., -6 for 6 months)
RETURN
CALCULATE([TotalSales],FILTER(ALL('DateTable'),'DateTable'[Date] >= StartDate &&'DateTable'[Date] <= DATE(SelectedYear, SelectedMonth, 1) - 1)) - 2 years ago
Hi,
I have solved a similar question in the attached file.
Hope this helps.
Oros
Post Prodigy
2 years agoAshish_Mathur
Super User
2 years agoYou are welcome.