Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

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

  • lbendlin's avatar
    lbendlin
    6 years ago

    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.

     

4 Replies

  • 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)

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      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 

      • lbendlin's avatar
        lbendlin
        Icon for Super User rankSuper User

        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.