Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

Power Query - Get data from another table if condition is met

Hi all,

 

I need your help to get data from table 2 if some conditions are met there, and this in power query. I have a ref that I can found in both table, and I need to retrieve the "to return value" if Date from table 1 is within Start and End date of table 2. There are overlap in date for the same ref in Table 2, in such case I just need the first value that match the critera. This is what I have:

 

Table 1

RefDate
105.01.2022
203.03.2023
101.03.2023
118.02.2022
313.08.2022
......

 

Table 2

RefStart DateEnd DateValue to return
101.01.200031.12.2002abc
101.01.202230.06.2022def
101.01.202230.11.2022azt
201.01.202331.03.2023uir

 

The result I am looking for

RefDateReturned value
105.01.2022def
203.03.2023uir
101.04.2023null
118.02.2022def
313.08.2022azt
.........

 

Thanks in advance for your help!

4 Replies

  • HealthyBob's avatar
    HealthyBob
    Regular Visitor

    Hi,

    maybe you can try Something Like that 

     

    = If( And("Date Table 1" > " start Date table 2", "Date Table 1"< "end Date Table2), Firstnonblank(value to Return, value to Return), "Else condition"))

     

    Im new with Firstnonblank, but it worked for me to Type in the returning value twice.

     

    Best

    • Anonymous's avatar
      Anonymous
      Not applicable

      That would be great, but you cannot even select any field from table 2 with a simple if statement

  • HealthyBob's avatar
    HealthyBob
    Regular Visitor

    Is IT because you See an Error or is it not selectable? Do you have the right linkage? Or is it just a Table as visual? Then you have to get the Data in the Backend Tables. Otherwise try to geht an measure feom your Table with calcualte(values( which you can select in the If Statement 

    • Anonymous's avatar
      Anonymous
      Not applicable

      Tables are well connected, however IF statement cannot compare a value from a cell to a table, I guess.