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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
EpicTriffid
Helper IV
Helper IV

Using Date Tables Properly

Hi all,

 

I have created a date table to map out academic years (Sept-Sept) based on actuals date (e.g. 01/01/2016 would be the 2015/16 Academic Year, whilst 01/09/2016 would be the 2016/17 Academic Year). An example of this is below:

 

date table ay.JPG

 

I created this using this code:

Date Table = 
VAR MinYear =
    YEAR ( MIN ( Query2[DateYear] ) )
VAR MaxYear =
    YEAR ( MAX ( Query2[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 )
        )
    )

 

I have related this to my Query table using the Academic Year (Short) column in the Date Table, as that is what is in the Query table.

 

So now I need to create a measure that returns the data for the current academic year that we are in (2019/20). My thinking was that I could write something like:

 

CurrentYear = CALCULATE(
    SUM(Query2[Total Student Count]),
    YEAR('Date Table'[Date]) = YEAR(TODAY()))

 

But what i need it to do is to look across the Date Table, and instead return me the academic year:

 

row.JPG

 

So it would see the current date, but when filtering the Total Student Count, it would filter out those records for 19/20. I previously just did YEAR(TODAY()) -1, but this would break as soon as we hit September, which is what the date table resolves, if only i can get the CALCULATE to work. I think it might be something like RELATED or LOOKUPVALUE but I don't know how to string them together.

 

I'm hoping that I can use this new date table to use the time intelligence functions to sort out trending and the like.

 

I really hope you can help.

 

Cheers,

 

Matt

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

I'm thinking:

 

CurrentYear = 
  VAR __Year = LOOKUPVALUE('Date Table'[Academic Calendar Year],'Date Table'[Date],TODAY())
RETURN
CALCULATE(
    SUM(Query2[Total Student Count]),
    'Date Table'[Academic Calendar Year]) = __Year
)

 

Not sure you will be able to do time intelligence. See if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
v-alq-msft
Community Support
Community Support

Hi, @EpicTriffid 

 

Based on your description, I created data to reproducce your scenario.

Table:

b1.png

 

Date Table:

 

 

Date Table = 
VAR MinYear =
    YEAR ( MIN ( 'Table'[Date] ) )
VAR MaxYear =
    YEAR ( MAX ( 'Table'[Date] ) )
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 )
        )
    )

 

 

 

There is a one-to-one relationship between two tables.

 

You may create a measure as below.

 

 

IsDisplay = 
var _academicyear = 
CALCULATETABLE(
    DISTINCT('Date Table'[Academic Year (Short)]),
    'Date Table'[Date] = TODAY()
)
var _currentvalue = SELECTEDVALUE('Date Table'[Academic Year (Short)])
return
IF(
    _currentvalue in _academicyear,
    1,0
)

 

 

 

Then you may put the measure in the visual level filter. Here is the result.

b2.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Community Champion
Community Champion

I'm thinking:

 

CurrentYear = 
  VAR __Year = LOOKUPVALUE('Date Table'[Academic Calendar Year],'Date Table'[Date],TODAY())
RETURN
CALCULATE(
    SUM(Query2[Total Student Count]),
    'Date Table'[Academic Calendar Year]) = __Year
)

 

Not sure you will be able to do time intelligence. See if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Thank you. This worked great. 

 

Like you said, I don't think I can use Time Intelligence with this, mostly as I think the DAX required would kill me!

 

However, I did quite easily move it forward 1, 3 and 5 Years, and was able to subtract this from the Current Year to get a difference so I get some semblance of Time Intelligence:

 

1 Year Trend = 
VAR OneYearDate = LOOKUPVALUE('Date Table'[Academic Calendar Year],'Date Table'[Date],TODAY())
RETURN

VAR OneYear = 
CALCULATE( 
    SUM(Query2[Total Student Count]),
    'Date Table'[Academic Calendar Year] = OneYearDate + 1
)
RETURN

OneYear - [CurrentYear]

 

 

 

 

Helpful resources

Announcements
Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors