Forum Discussion
Calculated column to show past month and this week
Hello everyone,
I have a calendar auto table that compromises of date tables.
I would like to have a calculated column that is something like this.
If the dates are in the current month, it will show on a weekly formated (refer to week-01 Dec 2024 and week-08 Dec 2024). If it's previous dates, it will be grouped by monthly basis (refer to Aug 2024, Sep 2024, etc).
| Month Aug'24 | Month Sep'24 | Month Oct'24 | Month Nov'24 | Week 01-Dec-2024 | Week 08-Dec-2024 |
I have already made a calculated column to show the week format.
I'm currently stuck at making the formula above to include the month clause as I stated above.
Let me know if there's anything else needed from my end.
Thanks!
Hi Anonymous , please try the formula below:
Group_Label =
VAR CurrentMonthStart = EOMONTH(TODAY(), -1) + 1
VAR CurrentDate = 'Calendar'[Date]
VAR IsCurrentMonth = CurrentDate >= CurrentMonthStart && CurrentDate <= EOMONTH(TODAY(), 0)
VAR WeekDayValue = WEEKDAY(CurrentDate, 2)
VAR WeekStart = CurrentDate - WeekDayValue + 1
VAR WeekLabel =
IF(
WeekDayValue <= 3,
"Week " & FORMAT(WeekStart, "dd-MMM-yyyy"),
"Week " & FORMAT(WeekStart + 7, "dd-MMM-yyyy")
)
RETURN
IF(
IsCurrentMonth,
WeekLabel, -- Weekly format for the current month
FORMAT(CurrentDate, "MMM yyyy") -- Monthly format for previous months
)Hi Anonymous
Create a new calculated column that groups dates into "weekly format" for the current month and "monthly format" for previous months. Here's how to modify your DAX code:Date_Grouping = VAR CurrentMonth = FORMAT(TODAY(), "YYYY-MM") VAR DateMonth = FORMAT('Calendar'[Date], "YYYY-MM") VAR WeekStart = 'Calendar'[Date] - WEEKDAY('Calendar'[Date], 2) + 1 VAR StartOfWeekLabel = "Week " & FORMAT(WeekStart, "dd-MMM-yyyy") RETURN IF( DateMonth = CurrentMonth, StartOfWeekLabel, FORMAT('Calendar'[Date], "MMM YYYY") )
3 Replies
- anmolmalviya05Super User
Hi Anonymous , please try the formula below:
Group_Label =
VAR CurrentMonthStart = EOMONTH(TODAY(), -1) + 1
VAR CurrentDate = 'Calendar'[Date]
VAR IsCurrentMonth = CurrentDate >= CurrentMonthStart && CurrentDate <= EOMONTH(TODAY(), 0)
VAR WeekDayValue = WEEKDAY(CurrentDate, 2)
VAR WeekStart = CurrentDate - WeekDayValue + 1
VAR WeekLabel =
IF(
WeekDayValue <= 3,
"Week " & FORMAT(WeekStart, "dd-MMM-yyyy"),
"Week " & FORMAT(WeekStart + 7, "dd-MMM-yyyy")
)
RETURN
IF(
IsCurrentMonth,
WeekLabel, -- Weekly format for the current month
FORMAT(CurrentDate, "MMM yyyy") -- Monthly format for previous months
) - Bibiano_GeraldoSuper User
Hi Anonymous
Create a new calculated column that groups dates into "weekly format" for the current month and "monthly format" for previous months. Here's how to modify your DAX code:Date_Grouping = VAR CurrentMonth = FORMAT(TODAY(), "YYYY-MM") VAR DateMonth = FORMAT('Calendar'[Date], "YYYY-MM") VAR WeekStart = 'Calendar'[Date] - WEEKDAY('Calendar'[Date], 2) + 1 VAR StartOfWeekLabel = "Week " & FORMAT(WeekStart, "dd-MMM-yyyy") RETURN IF( DateMonth = CurrentMonth, StartOfWeekLabel, FORMAT('Calendar'[Date], "MMM YYYY") ) - AnonymousNot applicable
Thank you so much!