Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Calendar data update

Hi Team,

 

What do I need to do to

a)  Add week to this dax code (Monday - Sunday)

b) Add a piece of code to take account of today's date date_to

 

Calendar =
VAR __MIN =
    DATE ( 2022, 1, 1 )
VAR __MAX =
    DATE ( 2024, 12, 31 )
VAR __BASE =
    CALENDAR ( __MIN, __MAX )
VAR __RESULT =
    ADDCOLUMNS (
        ADDCOLUMNS (
            __BASE,
            "Year", YEAR ( [Date] ),
            "Month Long", FORMAT ( [Date], "mmmm" ),
            "Month Short", FORMAT ( [Date], "mmm" ),
            "Month Number", MONTH ( [Date] ),
            "Month and Year", FORMAT ( [Date], "mmm-yy" ),
            "YYYYMM", FORMAT ( [Date], "YYYYMM" ),
            "Quarter", "Q" & QUARTER ( [Date] ),
            "Day of Week Long", FORMAT ( [Date], "dddd" ),
            "Day of Week Short", FORMAT ( [Date], "ddd" ),
            "Day Sort", WEEKDAY ( [Date], 1 ),
            "Week of Year", WEEKNUM ( [Date] ),
            "Week Ending Saturday",
                VAR __DAY =
                    WEEKDAY ( [Date] ) - 7
                RETURN
                    [Date] - __DAY,
            "Week Ending Wednesday",
                VAR __DAY =
                    WEEKDAY ( [Date] ) - 4
                RETURN
                    [Date] - __DAY
        ),
        "Week Starting Thursday", [Week Ending Wednesday] - 6
    )
RETURN
    __RESULT
  • Simply add this new calculated column to your data table to get the week number

     

     

    Week = 
    // week starts Monday and ends Sunday
    YEAR('Calendar'[Date]) 
    & "-" &
    FORMAT(WEEKNUM('Calendar'[Date],2),"00")

     

     

    Please click "accept solution" and the thumbs up buttons 

1 Reply

  • Simply add this new calculated column to your data table to get the week number

     

     

    Week = 
    // week starts Monday and ends Sunday
    YEAR('Calendar'[Date]) 
    & "-" &
    FORMAT(WEEKNUM('Calendar'[Date],2),"00")

     

     

    Please click "accept solution" and the thumbs up buttons