Hello,
I have a standard date table. I’d like to create 5 flag columns that indicate if the day, week, month, quarter or year is the current or previous period, as follows:
-Today Flag:** If the date is today’s date, the value should be “Today”. The row with the previous day’s value should be “Previous Day”. All other rows that aren’t flagged as “today” or “previous day” should be flagged “Other”.
-This Week Flag:** If today’s date falls in the current week, then the value for all rows in this week should be “this week”. The previous week’s values should be “Previous Week”. All others should be “Other”
-This Month Flag:** if today’s date falls in the current month, then all rows in that month should be “this month”. The previous month values should be “Previous Month”. All others should be “Other”.
-This Quarter Flag:** if today’s date falls in the current quarter, then all rows in that quarter should be “This Quarter”. The previous quarter values should be “Previous Quarter”. All others should be “Other”
-This Year Flag:** if today’s date falls in the current year, then all rows within that year should be “This Year”. The rows in the previous year should be “Previous Year”. All others should be “Other”.
As the data changes, then the flags should change dynamically such that the flags are always marking the current and previous period.
I wrote the dax for the Today Flag, as follows:
Today Flag = SWITCH(TRUE(),
‘Dates’[Date] = TODAY(), “Today”,
‘Dates’[Date] = TODAY()-1, “Previous Day”, “Other”)
I was also able to successfully write the DAX for the This Week Flag:
This Week Flag = SWITCH(TRUE(),
WEEKNUM ( Dates[Date] ) = WEEKNUM ( TODAY () ) && YEAR(Dates[Date]) = YEAR(TODAY()), “This Week”,
WEEKNUM(Dates[Date]) = WEEKNUM(TODAY()) - 1 && YEAR(Dates[Date]) = YEAR(TODAY()), “Previous Week”, “Other”)
I attempted to create the “This Month Flag” with the following DAX:
This Month Flag = SWITCH(TRUE(),
MONTH (Dates[Date]) = month ( TODAY () ) && YEAR(Dates[Date]) = YEAR(TODAY()), “This Month”,
MONTH(Dates[Date]) = MONTH(NOW())-1 && YEAR(Dates[Date]) = YEAR(TODAY()), “Previous Month”, “Other”)
The result is correct for “This Month”, however it does not correctly flag “Previous Month”. All other results are “Other”.
However, I’m not sure how to do the remaining flags for month, quarter and year.
If you know how to create these flag columns using DAX, please share!
Thanks,
Pete