Vlookup within results of a multiple-match lookup - arrays

I am trying to find a way to return values from a table like the bottom table:
The tables are provided externally and my understanding is that I can't run filters or sorts as the table is full of extra irrelevant data that would not sort properly across all columns.
I'm approaching this twofold:
firstly, I wanted to return the row information for any entry in the table that has a CPT matching the lookup value.
Second, (where I'm stuck)--when the lookup returns a DESC that corresponds to a matched CPT, the goal would be to also pull in any Code A/Code B entries that correspond to that DESC value.
I found an existing formula that worked for the first part, shown below. (apologies for formatting--SO keeps flagging my draft as having unformatted code).
IFERROR(INDEX($B$3:$B$3000,SMALL(IF(I$2=$A$3:$A$3000,ROW($A$3:$A$3000)- MIN(ROW($A$3:$A$3000))+1,""), ROW()-1)),"")
Currently, the aforementioned formula does return the DESC entries for any matching CPTs and I use vlookup to pull the rest of the relevant columns for a corresponding row.
I'm coming up short in cases where there are multiple Code A/Code B entries for a given DESC, as the lookup only returns information for the row containing the matching CPT and not any relevant codes contained in subsequent rows.
I was thinking I'd have to use something similar to the existing lookup formula to identify a matched row and then display any subsequent rows containing Code entries until the next row with a non-blank CPT entry.
Unfortunately, I don't know if that's actually the best way to approach this. Any resources/suggestions are greatly appreciated.

Related

IFERROR MATCH formula not searching whole sheet

We use a sheet to look up information. There are 936 rows and will get more as time goes on, however the query returns a blank result (as it should) after row 600, how do i change what the search/lookup area so it will search the whole table on a separate sheet and return the results?
=IFERROR(IF($D$5=""," ",INDEX(allvehicles2,(MATCH($D$5,indexes2,0)),7))," ")
Tried to alter the selection and even moving to another sheet but would not return the results.
If you are able to, try using Tables with the XLOOKUP function.
It simplifies the formula and the table will automatically grow as data is added to it.
This ensures that the formula will use all the data.
Make sure that the data you are using to lookup against is continuous.
That is no empty rows or columns.
Ensure that it has headings.
Turn it into a table by selecting it and pressing Ctrl + T.
You can change the name of your table by selecting the data and not the headers.
Then use the Name box to change the name.
Then use the XLOOKUP function, with the lookup_array and return_array values each being a column in the table. If the value is not found, an empty string will be returned.
Formula structure
=XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found])
Example formula based on the screenshot
=XLOOKUP(A2,MyTableName[Key],MyTableName[Value 6],"")

How to add values in cells ONLY when other columns contain data from a query result

Link to example file:
https://docs.google.com/spreadsheets/d/1dCQSHWjndejkyyw-chJkBjfHgzEGYoRdXmPTNKu7ykg/edit?usp=sharing
The tab "Source data" contains the data to be used in the query on the tab "Query output". The tab "Desired result" shows what I would like the end result to look like.
The goal I'm trying to achieve is to have the formula in cell A2 on the tab "Query output" to populate the data in all four of the columns, so that it looks exactly like the "Desired result" tab. I know I can get the same result simply by entering additional formulas in C2 and D2, but this is not the objective, I need the results to come specifically from the single formula in A2.
The information in the "Additional data 1" column should simply repeat the word "Test" for every row that contains data in the first two columns. The information in the "Additional data 2" column should simply repeat the data from cell 'Source data'!A1 for every row that contains data in the first two columns.
Please feel free to edit the example file as it only contains dummy data. If you like, you can copy the tab "Query output" to create your own working formula for illustrative purposes.
EDIT:
I'm thinking along the lines of creating an array that consists of the required data for the columns "Additional data 1" and "Additional data 2" and then combining that array with the array of the query result which provides the first two columns. I've been experimenting with this in various ways, but so far the only result I have achieved is an error on the first cell of the query results. I also have no idea yet how I could make sure that the second array contains an equal amount of rows to the query result.
You can add static data into query:
=QUERY('Source data'!A3:B,"SELECT A,B, 'Test', '" & 'Source data'!A1 &"' WHERE A IS NOT NULL LABEL A '', B '', 'Test' '', '" & 'Source data'!A1 &"' ''")
Many thanks to #basic for the provided assistance! The insights were a great help to solving my issue. That said, I have muddled along a bit, and I've come up with a slightly different solution which I find better suited as it gives true blank values instead of a column filled with spaces.
First of all, instead of querying directly on the source data, I built an array and queried on that. I used the two existing columns (A and B) from the source data and added a third column to the array which does not exist in the source data. In order to make sure that the third column would consist of blank values, I used the IFERROR formula.
=IFERROR(0/0)
The formula above returns a blank because dividing by zero forces an error and the IFERROR method returns a blank unless an alternative return value is specified.
In order to be able to use this formula in an array however, it had to be tweaked slightly, because as it is it would only return a single blank cell value instead of a column of blank values. To do this, I used an already existing column from the source data, and then encapsulated it in an ARRAYFORMULA.
=ARRAYFORMULA(IFERROR('Source data'!A3:A/0))
Using this, the resulting array has the following formula.
=ARRAYFORMULA({'Source data'!A3:A,'Source data'!B3:B,IFERROR('Source data'!A3:A/0)})
This creates an array consisting of the two original columns A and B from the source data, plus an additional third column filled with blank values. This array can now be queried upon, and using the tricks previously provided by #basic the desired result as specified in the original question can be achieved.
Due to the query now being used upon a user-defined array, the columns in the SELECT statement now have to be referred to as Col1, Col2, Col3, instead of A, B, C. The final formula now looks like this.
=QUERY(ARRAYFORMULA({'Source data'!A3:A,'Source data'!B3:B,IFERROR('Source data'!A3:A/0)}),"SELECT Col1,Col2,'Test',Col3,'"&'Source data'!A1&"' WHERE Col1 IS NOT NULL LABEL 'Test' '','"&'Source data'!A1&"' ''")
I hope this information may prove of use to someone else as well.

How to Use Excel Spill Range To Convert Multi-Column Array into Two Column Array

I'm trying to create a spill-range solution to turn a list of dates and multiple columns of names into a structured two columns of data. I can do this using VBA, but because this will be automated and web-based, I need a spill-range solution.
A sample file of my situation can be found in this file.
As you'll see below, I have a list of a set of employees ("slackers") who have requested vacation/PTO during December. I've created a list of two spill range formulas that are:
A Column listing all days December
A list of slackers requesting the day off (array going horizontal).
Part 2 presents the problem as the the number of slackers is inconsistent and I'm not sure how to create additional dates for each row. Thus my problem is how to structure a filter/Array formula to list each employee, by day.
In the following tab, you can see my desired outcome. I've used a macro to generate this, but because this is web-based, I cannot use it.
I've tried a variety of mixing and matching array formulas and filters but cannot find a way to populate the date with each name.
While my question is scoped to addressing this conversion from multi-column to 2-column approach, I am happy to hear comments addressing the overall concept.
Here it is with your datatable:
=LET(
end, PtoRequestsTable[End],
strt, PtoRequestsTable[Start],
us, PtoRequestsTable[Slacker],
usCnt, COUNTA(us),
lst, DATE(YEAR(TODAY()),12,1),
led, DATE(YEAR(TODAY()),12,31),
dtSq, INT(SEQUENCE((led-lst+1)*usCnt,,lst,1/usCnt)),
md, MOD(SEQUENCE((led-lst+1)*usCnt,,0),usCnt)+1,
ussl, IF((INDEX(end,md)>=dtSq)*(INDEX(strt,md)<=dtSq),INDEX(us,md),""),
SORT(FILTER(CHOOSE({1,2},dtSq,ussl),ussl<>""),1,-1)
)
It will automatically grow and shrink with the table. It also has the start and end dates as inputs.
You may need to adjust maxWidth if there are more than 8 potential slackers.
=LET(maxWidth,8,
days,ByDay!A2#,
slackerBox,OFFSET(days,,1,,maxWidth),
ndx,SEQUENCE(ROWS(days)*maxWidth),
ndxDay,INT(ndx-1)/maxWidth+1,
slackerList,INDEX(slackerBox,ndxDay,MOD(ndx-1,maxWidth)+1),
FILTER(CHOOSE({1,2},INDEX(days,ndxDay),slackerList),slackerList<>0))

Excel: Array formula to return the column data that matches multiple criteria

I would like to submit an Excel problem I tried to solve for the past few days. I am not allowed to use macro, only formulas.
I have 3 tables (see link):
The first one (purple) contain a list of employees and their initials, no duplicates;
The second one (blue) is the main database (+ 500 columns), where all the employees codes are reported and each check mark (ü) represent the specific options related to that employee; this table is always modified (employees come and go, options are added, etc.);
The third one (Green) is the table that we need to make functional; when we select the name of an employee (yellow), it returns the matching initials (orange); we would like this table to automatically search the initials of the employee in the blue table heading and return the Codes that match the check marks in the respective column; I need a particular array formula to do so.
As you can notice, I calculated various formulas tests and, although I might be on the right path, I lack the necessary skills to create a complex formula that will return the matching codes of the preferences (check marks) from the array column. Does someone have an idea what should be modified to achieve this goal ? Thank you all for any solution you can propose.
Excel file

Excel array function return all fields found with index and match

Here is the array function I am using:
=IFERROR(INDEX('Master Data'!$D$2:$D$153,MATCH(1,(B9='Master Data'!$J$2:$J$153)*('Master Data'!$W$2:$W$153=1),FALSE)),"")
Where D is the name of a project, J is a persons name and W is a flag to check if they are assigned to a project either equal to 0 or 1. B is also an instance of the persons name that is built up from a seperate list.
It basically references the master data and returns any rows with the criteria specified. However a single person may have two instances where the assigned flag is equal to 1 and thus as the master data is filtered different results are given back by the function.
Another problem I have is that the persons name is not repeated either so maybe the best way would be to start populating the names in the assigned table from the master data as well.
As requested here is an slight example of the data. On the left is the master data, the middle is the assigned table thats being built and the right is the list of employees that builds up the names in the assigned table.
Please note that there is two instances of david smith in the master data but only one in the assigned table as its being built with the employees list.
What I was thinking was to build up the names in the assigned table from the master data using an array where the assigned indicator is equal to 1 and to completely scrap the employees list, but I'm really unsure if this is possible or how to go about it.
Or even if there was some sort of way to select a few columns from the master data where the assigned indicator = 1?
Not sure if I understood it right. But the problem how to list multiple lookup results is achievable with SMALL function in combination with getting an array of ROW numbers.
For example have a sheet like this:
Then formulas are:
F4 downwards:
=COUNTIFS($B:$B,$E4,$C:$C,1)
G4 and then copied in G4:J8:
{=INDEX($A$1:$A$1000,SMALL(IF($B$1:$B$1000=$E4,IF($C$1:$C$1000=1,ROW($1:$1000))),COLUMN(A:A)))}
But if the goal is only to have a filtered list of all assigned resources, then the formulas could be
E13:
{=INDEX($B$1:$B$1000,MATCH(1,($C$1:$C$1000=1)*1,0))}
E14 downwards:
{=INDEX($B$1:$B$1000,MATCH(1,(COUNTIF($E$13:$E13,$B$1:$B$1000)=0)*($C$1:$C$1000=1),0))}
Formulas in {} are array formulas. These are entered into the cell without the curly brackets and then [Ctrl]+[Shift]+[Enter] is pressed to finish.
I have not handled the error values for better understanding the formulas. You can later hide the error values with IFERROR. You seems to know how to do this.

Resources