Forum Discussion

GPH's avatar
GPH
Frequent Visitor
8 years ago
Solved

Return a value based on date start and date end

Need help please! 

 

I need to return a value based on a date range. I have two tables, one has the date (which i need to return the id) and the other has the date start and date end of the coresponding ids. I have made two smaller tables as an example. 

My first table provides the date start and date end of each id. I need to populate the id column in the table below. 

 

 

 

These tables are just mockups, I have a much larger tables (with more ids and dates) loaded into power bi already. I could do it in excel using a VLOOKUP but can not work out how to make it work in Power BI. 

 

Any help would be much appreciated! 

  • If I name the first table to Intervals and the second to Dates you could try:

    Id = 
    CALCULATE(
           VALUES(Intervals[Id]);
           FILTER(
               Intervals;
               Intervals[Date_Start] <= EARLIER(Dates[Date])
               && Intervals[Date_End] >= EARLIER(Dates[Date])
           )
    )

2 Replies

  • Johanno's avatar
    Johanno
    Icon for Continued Contributor rankContinued Contributor

    If I name the first table to Intervals and the second to Dates you could try:

    Id = 
    CALCULATE(
           VALUES(Intervals[Id]);
           FILTER(
               Intervals;
               Intervals[Date_Start] <= EARLIER(Dates[Date])
               && Intervals[Date_End] >= EARLIER(Dates[Date])
           )
    )
    • GPH's avatar
      GPH
      Frequent Visitor

      That is perfect! thankyou so much!