Multi-condition lookup with dates and text

大城市里の小女人 提交于 2019-12-12 02:49:42

问题


I have been melting my brain trying to work out the formula i need for a multiple conditional lookup.

I have two data sets, one is job data and the other is contract data. The job data contains customer name, location of job and date of job. I need to find out if the job was contracted when it took place, and if it was return a value from column N in the contract data.

The problem comes when i try to use the date ranges, as there are frequently more than one contract per customer.

So for example, in my job data:-

CUSTOMER | LOCATION | JOB DATE

Cust A | Port A | 01/01/2014

Cust A | Port B | 01/02/2014

Customer A had a contract in port B that expired on 21st Feb 2014, so here i would want it to return the value from column N in my contract data as the job was under contract. Customer A did not have a contract in port A at the time of the job, so i would want it to return 'no contract'.

Contract data has columns containing customer name, port name, and a start and end date value, as well as my lookup category.

I think i need to be using index / match but i can't seem to get them to work with my date ranges. Is there another type of lookup i can use to get this to work?

Please help, I'm losing the plot!

Thanks :)


回答1:


You can use two approaches here:

  1. In both result and source tables make a helper column that concatenates all three values like this: =A2&B2&C2. So that you get something like 'Cust APort A01/01/2014'. That is, you get a unique value by which you can identify the row. You can add delimiter if needed: =A2&"|"&B2&"|"&C2. Then you can perform VLOOKUP by this value.

  2. You can add a helper column with row number (1, 2, 3 ...) in source table. Then you can use =SUMIFS(<row_number_column>,<source_condition_column_1>,<condition_1>,<source_condition_column_2>,<condition_2>,...) to return the row number of source table that matches all three conditions. You can use this row number to perform INDEX or whatever is needed. But BE CAREFUL: check that there are only unique combinations of all three columns in source table, otherwise this approach may return wrong results. I.e. if matching conditions are met in rows 3 and 7 it will return 10 which is completely wrong.



来源:https://stackoverflow.com/questions/24140720/multi-condition-lookup-with-dates-and-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!