Forum Discussion
Rolling 6 months dax
Hi,
I want to build a DAX flag for rolling 6 months that includes the current month
Can you please help
Example
Today is 8th Jan 2025 so Rolling 6 months flag would look like this
| Calendar Month | Calendar Year | Rolling 6 Flag |
| 2024 | 5 | No |
| 2024 | 6 | No |
| 2024 | 7 | No |
| 2024 | 8 | Yes |
| 2024 | 9 | Yes |
| 2024 | 10 | Yes |
| 2024 | 11 | Yes |
| 2024 | 12 | Yes |
| 2025 | 1 | Yes |
klehar , Try using and create a new calculated column
Rolling 6 Flag =
VAR CurrentDate = TODAY()
VAR CurrentYear = YEAR(CurrentDate)
VAR CurrentMonth = MONTH(CurrentDate)
VAR StartDate = EDATE(CurrentDate, -5) -- 5 months before the current month
RETURN
IF(
[Calendar Year] * 100 + [Calendar Month] >= YEAR(StartDate) * 100 + MONTH(StartDate) &&
[Calendar Year] * 100 + [Calendar Month] <= CurrentYear * 100 + CurrentMonth,
"Yes",
"No"
)
3 Replies
- bhanu_gautam
Super User
klehar , Try using and create a new calculated column
Rolling 6 Flag =
VAR CurrentDate = TODAY()
VAR CurrentYear = YEAR(CurrentDate)
VAR CurrentMonth = MONTH(CurrentDate)
VAR StartDate = EDATE(CurrentDate, -5) -- 5 months before the current month
RETURN
IF(
[Calendar Year] * 100 + [Calendar Month] >= YEAR(StartDate) * 100 + MONTH(StartDate) &&
[Calendar Year] * 100 + [Calendar Month] <= CurrentYear * 100 + CurrentMonth,
"Yes",
"No"
) - klehar
Helper V
can you please give me the pbi. Im unable to replicate.
Also if you can explain the logic in the IF part
- bhanu_gautam
Super User
klehar , Please find the PBIX file and I have written DAX now in more simplified way
Rolling 6 Flag =VAR CurrentDate = TODAY() -- Replace with TODAY() for dynamic calculationVAR StartDate = EOMONTH(CurrentDate, -5) + 1VAR EndDate = EOMONTH(CurrentDate, 0)RETURNIF('DateTable'[Date] >= StartDate && 'DateTable'[Date] <= EndDate,"Yes","No")CurrentDate captures today's date.
StartDate calculates the first day of the month 5 months before the current month.
EndDate calculates the last day of the current month.
The IF statement checks if the date in the Date table falls between StartDate and EndDate, and assigns "Yes" or "No" accordingly.