Array to lookup multiple columns and take another columns information

南笙酒味 提交于 2020-01-25 07:25:55

问题


I am trying to lookup a part number in a separate table array, the same value could be in multiple rows. The formula should find each instance of the value in the other table, move to a date column and determine which months the value exists in and which row it belongs to. The entire table B3:F15 should be automated. I have attached an image with proper explanation of what I am trying to accomplish if at all possible.

The formulas would be entered into B3:F15. These are the cells where the data will get pulled into. Each row will search for its corresponding Part Number in column A. I.e, B3 to F3 is only looking for A3 data. The rows are used to determine if a Part number in L2:P4 matches their row value in Column A and if was used in that month belonging to months B2:F2. If the Part number was used in the corresponding month then it will output the Plant # from Column I. In some cases the Part numbers in L2:P4 can exist in multiple rows, but they are unique to each column.

As an example I have manually filled in data for PN1001 and PN1021. For PN1001, this belongs to B3:F3. Each cell in B3:F3 will search the array L2:P4 and realize it is found only once and in M4, so it will look at the dates from its row, J4 and K4, and determine which months it was used in. Since it was used in Jan, Feb, and Mar, it will output the Plant # into D3, E3, F3. In the example of PN1021 it is the same but in this case PN1021 exists in L2 and L4, so it will take the date of J2,K2, and J4,K4.

Some Part numbers can be a combination of letters and numbers, some may just be numbers.

In terms of how to build the formula I am not sure what combination of Index/Match/Lookup I should be using. My theory is that each cell in B3:F15 would include a formula that be =MATCH(Lookup(columnA with L3:P4)) (but how do you get it to lookup multiple instances??) Some research lead me to use this concept to find multiple instances and point to the row #.

SMALL(IF(Lookup Range = Lookup Value, Row(Lookup Range),Row ()-# of rows below start row of Lookup Range)

Once I can find each instance, then Index the row and compare if the cell in B3 is greater than J3 and less than K3 to determine the months which should have a value entered. IFYES, then output column I from the row number.

If you have any better solutions or ideas to perform this action then please provide feedback. Thanks in advance for the support.


回答1:


I think the formula below will do what you want. I created a table out of your I1:P4 data, and used structured references, as I find it easier to follow.

B3: =IFERROR(
   INDEX(partsTbl,
           MAX(
                    ($A3=partsTbl)*
                      (B$2>DATE(YEAR(partsTbl[[Test Start Date]:[Test Start Date]]),MONTH(partsTbl[[Test Start Date]:[Test Start Date]]),0))*
                      (B$2<DATE(YEAR(partsTbl[[Test Finish Date]:[Test Finish Date]]),MONTH(partsTbl[[Test Finish Date]:[Test Finish Date]])+1,1))*
                      ROW(partsTbl)-ROW(partsTbl[#Headers])),
                      1),
  "")
  • $A3=partsTbl returns a 2D array like {FALSE,FALSE,TRUE,FALSE;FALSE,FALSE, …} to find the part number in the table
  • Since your start/finish dates in the partsTbl are not always at the beginning/end of the month, we need to convert them to such before we compare the dates in B2:F2
    • (B$2>DATE(YEAR(partsTbl[[Test Start Date]:[Test Start Date]]),MONTH(partsTbl[[Test Start Date]:[Test Start Date]]),0))
  • And similar for the end of the month.
  • We now have a 2D-array of {FALSE,FALSE,TRUE,FALSE...} where the TRUE matches the part number as filtered by the dates.
  • ROW(partsTbl) returns a matching array of the row numbers in the table (and we subtract the row number of the Header row to determine the row within the data).
  • When we do our multiplication, we then get an array where the largest value will be the desired row
  • INDEX, referencing column 1, will then return the appropriate Plant #



来源:https://stackoverflow.com/questions/59216587/array-to-lookup-multiple-columns-and-take-another-columns-information

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