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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
MattSwan
Frequent Visitor

Date Range Lookup Across 2 Tables to Populate a Column with Associated Valuess

Hi all,

 

I'm trying to replicate similar functionality to a VLOOKUP in Excel with range lookup set to TRUE.

 

I have two tables.

 

Collections has a date column.

 

Academic Years has a column called Academic Year and two date columns that specify a date range Start Date and End Date.

 

Table 1: Collections

 

Result Date
01/09/2020
05/05/2021
02/10/2021
02/02/2022

 

 

Table 2: Academic Year       

 

Academic Year    Start Date     End Date   
2020/2021        01/09/2020     31/08/2021
2021/2022        01/09/2021     31/08/2020

 

 

I would like to creat a column in the Collection table that looks up the Result Date in the Academic Year table and if it falls between the Start Date and End Date Display the Academic Year. Like this:

 

ResultDate       Academic Year
01/09/2020       2020/2021
05/05/2021       2020/2021
02/10/2021       2021/2022
02/02/2022       2021/2022

    

I've done some searching to see if I could find a solution. The code I have so far is below. However, this results in a blank column.

 

Academic Year = 
CALCULATE (
    SELECTEDVALUE ( 'Academic Years'[Academic Year] ),
    FILTER (
        'Academic Years',
        SELECTEDVALUE(Collections[Result Date]) >= 'Academic Years'[Start Date]
            && SELECTEDVALUE(Collections[Result Date]) <= 'Academic Years'[End Date] 
    )
)

 

Any assistance would be much appreciated.

 

1 ACCEPTED SOLUTION
v-robertq-msft
Community Support
Community Support

Hi, @MattSwan 

According to your description, I can roughly understand your requirement, I think you can try to create a calculated column in the table ‘Collections’ like this to achieve your requirement

Academic Year =

CALCULATE(MAX('Academic Year'[Academic Year]),FILTER(ALL('Academic Year'),[Start Date]<=EARLIER(Collections[Result Date])&&[End Date]>EARLIER(Collections[Result Date])))

 

And you can get what you want, like this:

vrobertqmsft_0-1636965784146.png

 

You can download my test pbix file below

Thank you very much!

 

Best Regards,

Community Support Team _Robert Qin

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

View solution in original post

3 REPLIES 3
v-robertq-msft
Community Support
Community Support

Hi, @MattSwan 

According to your description, I can roughly understand your requirement, I think you can try to create a calculated column in the table ‘Collections’ like this to achieve your requirement

Academic Year =

CALCULATE(MAX('Academic Year'[Academic Year]),FILTER(ALL('Academic Year'),[Start Date]<=EARLIER(Collections[Result Date])&&[End Date]>EARLIER(Collections[Result Date])))

 

And you can get what you want, like this:

vrobertqmsft_0-1636965784146.png

 

You can download my test pbix file below

Thank you very much!

 

Best Regards,

Community Support Team _Robert Qin

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

Yes thank you! I can't pretend to know exactly what's going on, but it works!

Greg_Deckler
Super User
Super User

@MattSwan See if LOOKUPVALUE Range helps: (1) LOOKUPVALUE Range - Microsoft Power BI Community



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.