Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
EpicTriffid
Helper IV
Helper IV

Unable to add year onto date table

Hi all,

 

So, I have the following code that I use to create a datetable for academic years (I work in an educational institution):

 

Date Table = 
VAR MinYear =
    YEAR ( MIN ( StaffTotals[DateYear] ) )
VAR MaxYear =
    YEAR ( MAX ( StaffTotals[DateYear] ) )
RETURN
    ADDCOLUMNS (
        FILTER (
            CALENDARAUTO (),
            AND ( YEAR ( [Date] ) >= MinYear, YEAR ( [Date] ) <= MaxYear )
        ),
        "Calendar Year", YEAR ( [Date] ),
        "Month Name", FORMAT ( [Date], "mmmm" ),
        "Month Number", MONTH ( [Date] ),
        "Academic Calendar Year", IF ( MONTH ( [Date] ) >= 9, YEAR ( [Date] ), YEAR ( [Date] ) - 1 ),
        "Academic Year", IF (
            MONTH ( [Date] ) >= 9,
            YEAR ( [Date] ) & "/"
                & RIGHT ( YEAR ( [Date] ) + 1, 2 ),
            YEAR ( [Date] ) - 1 & "/"
                & RIGHT ( YEAR ( [Date] ) , 2 )
                        ),
        "Academic Year (Short)", IF (
            MONTH ( [Date] ) >= 9,
            RIGHT ( YEAR ( [Date] ), 2 ) & "/"
                & RIGHT ( YEAR ( [Date] ) + 1, 2 ),
            RIGHT ( YEAR ( [Date] ) - 1, 2 ) & "/"
                & RIGHT ( YEAR ( [Date] ), 2 )
        ),
        "Std Week Number",
            WEEKNUM([Date],2
            ),
        "Week Number", 
        VAR stdWeekNum = 
            WEEKNUM([Date],2)
        VAR academicWeekNum = 
            stdWeekNum - WEEKNUM(DATE(YEAR([Date]),7,29),2)
        RETURN
        IF(academicWeekNum <= 0, 52 + academicWeekNum, academicWeekNum)
    )

 

This will make my date table between the lowest and highest possible year in my data. However, I want to be able to add a year onto this datetable (i.e. make it longer), so that i get the values between my lowest and highest possible year plus one. (e.g. my data currently runs between 2017 and 2022. I want a datetable that runs between 2017 and 2023). 

 

I figure that I need to make the change in my setting on the MaxYear variable but nothing works. I have tried DATEADD, a simple + 1 onto the variable, adding an additional variable and adding 1 to that, but can't get it to work.

 

Am I missing something simple here?

1 ACCEPTED SOLUTION
ppm1
Solution Sage
Solution Sage

Please try this instead.

Date Table =
VAR MinYear =
    YEAR ( MIN ( StaffTotals[DateYear] ) )
VAR MaxYear =
    YEAR ( MAX ( StaffTotals[DateYear] ) )
RETURN
    ADDCOLUMNS (
        CALENDAR ( DATE ( MinYear, 1, 1 ), DATE ( MAXYEAR + 1, 12, 31 ) ),
        "Calendar Year", YEAR ( [Date] ),
        "Month Name", FORMAT ( [Date], "mmmm" ),
        "Month Number", MONTH ( [Date] ),
        "Academic Calendar Year",
            IF ( MONTH ( [Date] ) >= 9, YEAR ( [Date] ), YEAR ( [Date] ) - 1 ),
        "Academic Year",
            IF (
                MONTH ( [Date] ) >= 9,
                YEAR ( [Date] ) & "/"
                    & RIGHT ( YEAR ( [Date] ) + 1, 2 ),
                YEAR ( [Date] ) - 1 & "/"
                    & RIGHT ( YEAR ( [Date] ), 2 )
            ),
        "Academic Year (Short)",
            IF (
                MONTH ( [Date] ) >= 9,
                RIGHT ( YEAR ( [Date] ), 2 ) & "/"
                    & RIGHT ( YEAR ( [Date] ) + 1, 2 ),
                RIGHT ( YEAR ( [Date] ) - 1, 2 ) & "/"
                    & RIGHT ( YEAR ( [Date] ), 2 )
            ),
        "Std Week Number", WEEKNUM ( [Date], 2 ),
        "Week Number",
            VAR stdWeekNum =
                WEEKNUM ( [Date], 2 )
            VAR academicWeekNum =
                stdWeekNum - WEEKNUM ( DATE ( YEAR ( [Date] ), 7, 29 ), 2 )
            RETURN
                IF ( academicWeekNum <= 0, 52 + academicWeekNum, academicWeekNum )
    )

Pat

Microsoft Employee

View solution in original post

1 REPLY 1
ppm1
Solution Sage
Solution Sage

Please try this instead.

Date Table =
VAR MinYear =
    YEAR ( MIN ( StaffTotals[DateYear] ) )
VAR MaxYear =
    YEAR ( MAX ( StaffTotals[DateYear] ) )
RETURN
    ADDCOLUMNS (
        CALENDAR ( DATE ( MinYear, 1, 1 ), DATE ( MAXYEAR + 1, 12, 31 ) ),
        "Calendar Year", YEAR ( [Date] ),
        "Month Name", FORMAT ( [Date], "mmmm" ),
        "Month Number", MONTH ( [Date] ),
        "Academic Calendar Year",
            IF ( MONTH ( [Date] ) >= 9, YEAR ( [Date] ), YEAR ( [Date] ) - 1 ),
        "Academic Year",
            IF (
                MONTH ( [Date] ) >= 9,
                YEAR ( [Date] ) & "/"
                    & RIGHT ( YEAR ( [Date] ) + 1, 2 ),
                YEAR ( [Date] ) - 1 & "/"
                    & RIGHT ( YEAR ( [Date] ), 2 )
            ),
        "Academic Year (Short)",
            IF (
                MONTH ( [Date] ) >= 9,
                RIGHT ( YEAR ( [Date] ), 2 ) & "/"
                    & RIGHT ( YEAR ( [Date] ) + 1, 2 ),
                RIGHT ( YEAR ( [Date] ) - 1, 2 ) & "/"
                    & RIGHT ( YEAR ( [Date] ), 2 )
            ),
        "Std Week Number", WEEKNUM ( [Date], 2 ),
        "Week Number",
            VAR stdWeekNum =
                WEEKNUM ( [Date], 2 )
            VAR academicWeekNum =
                stdWeekNum - WEEKNUM ( DATE ( YEAR ( [Date] ), 7, 29 ), 2 )
            RETURN
                IF ( academicWeekNum <= 0, 52 + academicWeekNum, academicWeekNum )
    )

Pat

Microsoft Employee

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.