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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Edds01388
Regular Visitor

Lookup between two dates

HI I have had a look at verious other similar problems but not been able to figure out how to replicate something I have.

 

In Excel - I used the following formula: =VLOOKUP(B353,A1:A55,3,TRUE)   where B353 is a date, and Row A1 is a date, and Row 3 is a value.

 

The problem is I have two tables

Table one - "tracker" with lots of fields, I want to insert a new coloumn into "tracker", which looks up the field 'tracker' [Date], then looks at the table "periods" and if the date is after "Pdatefrom" but before "Pdateto" , then give the value in the cell "PTitle".

 

Example data

Column A = Pdatefrom

Column B - Pdateto

Column C = PTitle

 

Screenshot 2023-11-21 125156.jpg

In simple terms vlookup or array lookup in excel would bascially look at the date, then check to see if that date is between two other dates then return the value from that table.

 

 

1 ACCEPTED SOLUTION

Hi @Edds01388 ,

Do you want this:
I will first show you the sample data:

vjunyantmsft_0-1700726850083.pngvjunyantmsft_1-1700726865359.png

Then use DAX to create a new column:

Title Matched = 
CALCULATE(
    FIRSTNONBLANK('Period ends'[Title], 1),
    FILTER(
        ALL('Period ends'),
        'Safety Tracker 2023'[Date] >= 'Period ends'[Pdatefrom] && 'Safety Tracker 2023'[Date] <= 'Period ends'[Pdateto]
    )
)

The final result is shown below:

vjunyantmsft_2-1700726935863.png

 

Best Regards,

Dino Tao

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

12 REPLIES 12
Edds01388
Regular Visitor

Screenshot 2023-11-23 083136.jpg

 

Thanks again - refreshed data and dates are now correct - just trying now to get this in number order.. not sure if this is possible

Hi @Edds01388 ,

Please try this way:

vjunyantmsft_0-1700786335973.png

vjunyantmsft_1-1700786375284.png

Then the final output is as following:

vjunyantmsft_2-1700786421140.png


Best Regards,
Dino Tao

Edds01388
Regular Visitor

Sorted it - my dates are wrong 🙂😂

Edds01388
Regular Visitor

Re-checked the data - for some reason its not checkinig it correctly - so a date in 2023 is appearing in a wrong period. 

Edds01388
Regular Visitor

Manged to get the chart created thank you again- couple of minor glitches which I am trying to figure out

1. X axes- getting this in a decent correct order  1,2,3,4 not how its showing

2. pulling a few wrong dates (but think I know why)

Screenshot 2023-11-23 081931.jpg

Edds01388
Regular Visitor

Hi thanks for the reponse 

Table "tracker  filed "date - this holds a date in the formate dd/mm/yy

Table "periods" - this has three fields - Date From, Date to and the Period. The new coloumn I am trying to create will look at the date, then compaire it with the dates in the "periods".

 

If a date in the "tracker" is within a date range in the "periods" (Pdatefrom" and "Pdateto") then is give the value for example

Tracker - Date 02/04/2009 - the new coloumn in the tracker will magically look at this date, go to the "period" table and check were this date is equal to or after to "Coloumn A" but before or equall too "Coloumn B", in this case the cell will return the value 1-2009/10

Date 24/07/2009 would give the value of 5-2009/10

 

This may help 

I have tried adding a new coloum into the "safety tracker 2023" table called PTitle with the following

Formula.jpgperiod shot.jpg

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

The above is the table which holds the dates and periods, I need to be able to look up the date from the "safety tracker" from the above values, then add in the value from the first coloum above if the date is between it.

Hi @Edds01388 ,

Do you want this:
I will first show you the sample data:

vjunyantmsft_0-1700726850083.pngvjunyantmsft_1-1700726865359.png

Then use DAX to create a new column:

Title Matched = 
CALCULATE(
    FIRSTNONBLANK('Period ends'[Title], 1),
    FILTER(
        ALL('Period ends'),
        'Safety Tracker 2023'[Date] >= 'Period ends'[Pdatefrom] && 'Safety Tracker 2023'[Date] <= 'Period ends'[Pdateto]
    )
)

The final result is shown below:

vjunyantmsft_2-1700726935863.png

 

Best Regards,

Dino Tao

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

Hi I have just found an issue.

For some reason its missing a single date out of each period. 

Screenshot 2024-02-06 143104.jpgScreenshot 2024-02-06 143314.jpg

 

The first image is a list of dates which the formula does not give a value - the second image is the list of dates (from and to) which is used to pull back the period, as you can see the first day after the start date is blank - help apprecaited

 

For example the Period from 17/09/2023 to 19/08/2023 - any date in that section should show 7-2023/24 - this works for every day BUT 18/09, this for each group 

Hi @Edds01388 

The column "Title Matched" is just the "Ptitle" you want, sorry I forgot to change the name.

Best Regards,
Dino Tao

You are a Genius!! Fantasic and many many thanks for this 🙂 I am good at excel, but this is something new for me

v-junyant-msft
Community Support
Community Support

Hi @Edds01388 ,

I apologize that I may not have understood which column you were hoping to compare. Is the 'tracker' [Date] column being compared to see if the date is between "Pdatefrom" and "Pdateto"? If so, please provide some additional data for the 'tracker' [Date] column.
Also I'm not sure what the "Period" column does in your screenshot?

vjunyantmsft_0-1700701966043.png

Based on the needs you describe, I will give you a reference DAX with which to create a new column:

PTitle = 
IF(
   'Table'[Date] >= 'periods'[Pdatefrom] && 'Table'[Date] <= 'periods'[Pdateto],
   TRUE(),
   FALSE()
)

You can change this DAX to suit your own situation.

Best Regards,

Dino Tao

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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