Forum Discussion

Southbound's avatar
Southbound
Regular Visitor
1 year ago
Solved

Year Week column

Hi 

 

I am struggling to get week year working. I have it year week so i can put it in the right order in tables but it doesnt get it right.

This is what I currently use

WeekYr = 
VAR _year = RIGHT(YEAR([DATE_TIME]), 2)  // Extract the last two digits of the year
VAR _week = WEEKNUM([DATE_TIME], 2)  // Extract the week number of the year with Monday as the first day of the week
// Adjust the week number if it is 53 to be included in Week 1 of the next year
VAR _adjustedWeek = IF(_week = 53, 1, _week)
// Format the week with leading zeros if needed
VAR _formattedWeek = FORMAT(_adjustedWeek, "00")
// Combine the formatted week and year
RETURN _year & "-" & _formattedWeek



all is fine except 30/12/2024 which shows as 24-01 anoyingly at the start of the year!

any ideas on how to fix?