Forum Discussion
how to lookup data from one table to another table using range for dynamic range of values
Hey
I have two table .
First Table
| Header Name | Base Unit | Start Engine Hours | Stop Engine Hours |
| A | HAJW210HKMG679924 | 10 | 30 |
| A | HAJSR26VTNG680048 | 980.9 | 1005.8 |
| A | HAJSR26HKMG679915 | 947.8 | 974.3 |
| B | HAJSR26HLMG679906 | 739.4 | 756.1 |
| B | HAJW210HKMG679924 | 1234.5 | 1283.7 |
| B | HAJSR26VTNG680048 | 1006.9 | 1051.7 |
| C | HAJSR26HKMG679915 | 789.5 | 875.8 |
| C | HAJW210VVNG680521 | 1.5 | 5.1 |
| C | HAJW210HKMG679924 | 1284.1 | 1333.5 |
| D | HAJSR22HKMG679922 | 254 | 270 |
| D | HAJSR22HPMG679921 | 290 | 310 |
| E | HAJSR22HPMG679921 | 290 | 310 |
| E | HAJSR22HPMG679921 | 290 | 310 |
| A | HAJW210HKMG679924 | 200 | 230
|
Second Table
| vin17 | ENG_HOURS | gps_timestamp | Average of AMBIENT_AIR_TEMPERATURE |
| HAJW210HKMG679924 | 10 | 7/29/2021 15:59 | 45 |
| HAJW210HKMG679924 | 20 | 7/29/2021 16:00 | 45 |
| HAJW210HKMG679924 | 30 | 7/29/2021 16:02 | 45 |
| HAJW210HKMG679924 | 40 | 7/29/2021 16:03 | 44 |
| HAJSR26VTNG680048 | 50 | 7/29/2021 16:04 | 42 |
| HAJSR26VTNG680048 | 60 | 7/29/2021 16:05 | 42 |
| HAJSR26VTNG680048 | 70 | 7/29/2021 16:06 | 43 |
| HAJW210HKMG679924 | 80 | 7/29/2021 16:07 | 44 |
| HAJW210HKMG679924 | 90 | 7/29/2021 16:08 | 44 |
| HAJW210HKMG679924 | 100 | 7/29/2021 16:09 | 45 |
| HAJW210HKMG679924 | 110 | 7/29/2021 16:10 | 45 |
| HAJW210HKMG679924 | 120 | 7/29/2021 16:11 | 46 |
| HAJW210HKMG679924 | 130 | 7/29/2021 16:12 | 46 |
| HAJW210HKMG679924 | 140 | 7/29/2021 16:13 | 46 |
| HAJW210HKMG679924 | 150 | 7/29/2021 16:14 | 46 |
| HAJW210HKMG679924 | 160 | 7/29/2021 16:15 | 46 |
| HAJW210HKMG679924 | 170 | 7/29/2021 16:16 | 46 |
| HAJW210HKMG679924 | 180 | 7/29/2021 16:18 | 47 |
| HAJW210HKMG679924 | 190 | 7/29/2021 16:19 | 47 |
| HAJW210HKMG679924 | 200 | 7/29/2021 16:20 | 47 |
| HAJW210HKMG679924 | 210 | 7/29/2021 16:23 | 48 |
| HAJW210HKMG679924 | 220 | 7/29/2021 16:26 | 49 |
| HAJW210HKMG679924 | 230 | 8/5/2021 14:44 | 27 |
| HAJSR26HLMG679906 | 229.8 | 8/6/2021 16:56 | 49 |
| HAJSR26HLMG679906 | 229.8 | 8/6/2021 16:57 | 49 |
| HAJSR26HLMG679906 | 229.8 | 8/6/2021 16:58 | 50 |
| HAJSR26HLMG679906 | 229.8 | 8/6/2021 16:59 | 51 |
| HAJSR26HLMG679906 | 229.9 | 8/6/2021 17:00 | 51 |
| HAJSR26HLMG679906 | 229.9 | 8/6/2021 17:01 | 51 |
| HAJSR26HLMG679906 | 229.9 | 8/6/2021 17:02 | 49 |
| HAJSR26HLMG679906 | 229.9 | 8/6/2021 17:03 | 48 |
| HAJSR26HLMG679906 | 229.9 | 8/6/2021 17:04 | 48 |
| HAJSR26HLMG679906 | 229.9 | 8/6/2021 17:05 | 48 |
| HAJSR26HLMG679906 | 230 | 8/6/2021 17:06 | 49 |
| HAJSR26HLMG679906 | 230 | 8/6/2021 17:07 | 48 |
| HAJSR26HLMG679906 | 230 | 8/6/2021 17:08 | 48 |
| HAJSR26HLMG679906 | 230 | 8/6/2021 17:09 | 46 |
| HAJSR26HLMG679906 | 230 | 8/6/2021 17:10 | 45 |
| HAJSR26HLMG679906 | 230 | 8/6/2021 17:11 | 47 |
| HAJSR26HLMG679906 | 230.1 | 8/6/2021 17:12 | 49 |
| HAJSR26HLMG679906 | 230.1 | 8/6/2021 17:13 | 51 |
| HAJSR26HLMG679906 | 230.1 | 8/6/2021 17:14 | 52 |
| HAJSR26HLMG679906 | 230.1 | 8/6/2021 17:15 | 54 |
| HAJSR26HLMG679906 | 230.1 | 8/6/2021 17:17 | 56 |
| HAJSR26HLMG679906 | 230.2 | 8/6/2021 17:19 | 57 |
| HAJSR26HLMG679906 | 230.2 | 8/6/2021 17:21 | 57 |
| HAJSR26HLMG679906 | 230.2 | 8/6/2021 17:22 | 57 |
| HAJSR26HLMG679906 | 230.2 | 8/6/2021 17:23 | 58 |
| HAJSR26HLMG679906 | 230.2 | 8/6/2021 17:24 | 58 |
| HAJSR26HLMG679906 | 230.3 | 8/6/2021 17:26 | 58 |
| HAJSR26HLMG679906 | 230.3 | 8/6/2021 17:30 | 58 |
| HAJSR26HLMG679906 | 230.4 | 8/6/2021 17:31 | 58 |
| HAJSR26HLMG679906 | 230.4 | 8/6/2021 17:33 | 58 |
| HAJSR26HLMG679906 | 230.4 | 8/6/2021 17:34 | 57 |
| HAJSR26HLMG679906 | 230.4 | 8/6/2021 17:35 | 58 |
| HAJSR26HLMG679906 | 230.5 | 8/6/2021 17:37 | 58 |
| HAJSR26HLMG679906 | 230.5 | 8/6/2021 17:38 | 58 |
| HAJSR26HLMG679906 | 230.5 | 8/6/2021 17:39 | 57 |
| HAJSR26HLMG679906 | 230.5 | 8/6/2021 17:40 | 57 |
| HAJSR26HLMG679906 | 230.5 | 8/6/2021 17:41 | 57 |
| HAJSR26HLMG679906 | 230.5 | 8/6/2021 17:42 | 57 |
| HAJSR26HLMG679906 | 230.6 | 8/6/2021 17:43 | 58 |
| HAJSR26HLMG679906 | 230.6 | 8/6/2021 17:44 | 57 |
How Can I lookup Header Name from Table one into Table two where Engine hours Fall between Start Engine Hours and Stop Engine Hours for each Base Unit ?
rahul632soni , new column in tabl2 , based on what I got
Maxx(filter(Table1, Table1[Base Unit] = Table2[vin17] && Table1[Start Engine Hours] <= Table2[ENG_HOURS] && Table1[End Engine Hours] >= Table2[ENG_HOURS] ) ,Table1[Header Name] )
you can use any other column based in need
refer 4 ways (related, relatedtable, lookupvalue, sumx/minx/maxx with filter) to copy data from one table to another
https://www.youtube.com/watch?v=Wu1mWxR23jU
https://www.youtube.com/watch?v=czNHt7UXIe8Winin table
DAX- Earlier, I should have known Earlier: https://www.youtube.com/watch?v=cN8AO3_vmlY&t=17820s
5 Replies
- bhelou
Responsive Resident
Hi , please can tyou share a sample ,this looks intresting to solve
- rahul632soni
Helper I
Hey bhelou
Actually I have two Different Table as you can see above .
Actulay I wanted to create a Visual through which, if i select Any Header from Table 1, i should get only those data From Table 2 where the Engine Hours is same as Start and Stop for Header A in Table 1 .
For that we are able to lookup the Header name from Table 1 to Table 2 with condition that the Engine Hours is in Between start and stop of Table 1 .
Solution shared by by amitchandak is working almost except for those cases where we have more than 1 start and stop Engine Hours for Header with Same Base Unit .
Let me Know if you required any other Information.
Regards
Rahul Soni
- amitchandak
Super User
rahul632soni , new column in tabl2 , based on what I got
Maxx(filter(Table1, Table1[Base Unit] = Table2[vin17] && Table1[Start Engine Hours] <= Table2[ENG_HOURS] && Table1[End Engine Hours] >= Table2[ENG_HOURS] ) ,Table1[Header Name] )
you can use any other column based in need
refer 4 ways (related, relatedtable, lookupvalue, sumx/minx/maxx with filter) to copy data from one table to another
https://www.youtube.com/watch?v=Wu1mWxR23jU
https://www.youtube.com/watch?v=czNHt7UXIe8Winin table
DAX- Earlier, I should have known Earlier: https://www.youtube.com/watch?v=cN8AO3_vmlY&t=17820s
- rahul632soni
Helper I
amitchandak Hey Thanks For Solution Its Working almost However IN Case where we have Same Header Attachewd to Same Base Unit Twice with Two Different Engine Hours Range , its not Doing Lookup for Example in Below Table we can see
Header Base Unit Start Stop A HAJW210HKMG679924 10 30 A HAJW210HKMG679924 200 230 Header A in Table 1 Attached to a Base Unit Twice with Two Different Tenure of Engine Hours , and Now After First Filter of VIn in Second Filter out of These Two Start and Stop Hours its not taking any , means i ma not getting any lookup value for this VIn.
Can you Help with this as well ?
Thanks in Advance
Regards
Rahul
- rahul632soni
Helper I
Hey amitchandak Thanks For Solution , its Working almost however in some cases where we have Header is attached to Same base unit more than once for Example , In Below Table
Header Base Unit Start Stop A HAJW210HKMG679924 10 30 A HAJW210HKMG679924 200 230 Header A is Attached to a Vin two times with two Different range of Engine Hours. In this scenario Lookup is not working
Can you Help with this also?
Regards
Rahul Soni