cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Frequent Visitor

Lookup start date and end date from another table

Hi, 

 

I got two tables, a calendar table (A) and table showing products' start and end dates (B). How can I get the result as shown in table C below (first date in the list would be current date and last date from the Product table, all dates in between should be listed)  

 

Calendar (A) 

Date

1/1/2020

1/2/2020
1/3/2020...

 

Product table (B)

ProductStart DateEnd Date
A6/1/20209/30/2020
B9/1/20209/30/2020
C1/1/202112/31/2021

 

Result (C)

DateProduct 1 Product 2 Product 3
6/7/2020Anullnull
6/8/2020Anullnull
...   
9/1/2020ABnull
...   
1/1/2021nullnullC
...   
12/31/2021nullnullC

 

Best regards,

 

Chris

1 ACCEPTED SOLUTION

the measure works fine for me. Have you put your fields in the right place? Date is from Calendar, Product is from Product. No linkage.

 

Annotation 2020-06-07 115329.png

View solution in original post

4 REPLIES 4
Super User III
Super User III

Pseudo code here

 

var d= max(date)

var Res = calculate(max([product]),[product start date]<=d,[product end date]>=d)

return res

 

This will result in the product name if in range, and BLANK if not.

 

EDIT: actual code here:  Note: no relationships between the tables!

 

 

live = 
var d = max('Calendar'[Date])
return CALCULATE(max('Product'[Product]),'Product'[Start Date]<=d,'Product'[End Date]>=d)

 

 

Hi Ibendlin,

 

and thanks for your input. I tried your measure, but it does only return one product for a specific date even though there might be several products with the same starting date? What am I doing wrong? 

 

However, I was thinking of how to solve this in M as a new table and not DAX as I need to make some further calculations to the data once I get this first step sorted out.

 

Best Regards,

 

Christer 

the measure works fine for me. Have you put your fields in the right place? Date is from Calendar, Product is from Product. No linkage.

 

Annotation 2020-06-07 115329.png

View solution in original post

Now I got it to work after seeing your formula. This solution will work, thanks a lot!

 

Chris

Helpful resources

Announcements
secondImage

Congratulations!

We are excited to announce the Power BI Super Users!

Wave Release 2

Check out the updates in Power BI.

Overview of Power BI 2020 release wave 2!

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

Top Solution Authors