Forum Discussion
Last X MONTHS based on selected MONTH
- 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.
Hi,
I have solved a similar question in the attached file.
Hope this helps.
Hi Ashish_Mathur ,
Thank you for your reply. Maybe I am missing something or a filter. How do I show the last six months, including the month that is selected. It is NOT showing in this selection.
- Ashish_Mathur2 years ago
Super User
It works fine in the file that i shared with you. Please study it carefully and then apply those formulas.
- Oros2 years ago
Post Prodigy
- Ashish_Mathur2 years ago
Super User
You are welcome.