Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

WEEKNUM returns false calendar weeks

Hello,    I am facing the following issue:  I am trying to calculate the calendar weeks with WEEKNUM() and have the following errors with the two different variants of the function: -Calendarweek...
  • dedelman_clng's avatar
    dedelman_clng
    5 years ago

    Anonymous  - I found a formula for ISO Year from a previous post. This should get you what you want.

     

    CalendarWeek =
    VAR __Wk =
        WEEKNUM ( DateTab[Date], 21 )
    VAR __ISOYr =
        IF (
            AND ( WEEKNUM ( DateTab[Date], 21 ) < 5, WEEKNUM ( DateTab[Date], 2 ) > 50 ),
            DateTab[Year] + 1,
            IF (
                AND ( WEEKNUM ( DateTab[Date], 21 ) > 50, WEEKNUM ( DateTab[Date], 2 ) < 5 ),
                DateTab[Year] - 1,
                DateTab[Year]
            )
        )
    RETURN
        __ISOYr & "-" & __Wk
    

     

    Hope this helps

    David