Return array based on titles - excel

I'm, looking for a way to return an array of text based off of titles or headers if you will. My brain isn't working today and I keep struggling to find the best method. I originally was going to have a bunch of IF statements and ran into problems, and I can't seem to figure out if Aggregate is a viable method.
Essentially if "Title 1" is selected from a drop down I would like to return the names within Title 1, and so on. If "All" is selected I would like all to populate from each title. The speed bumps I have is that some names repeat and I only want to show each name once always in alphabetical order. Can someone please get me started on how to tackle this?

In Excel O365 with the FILTER function, you can do this with a helper column (which you can hide, or position elsewhere).
I created a Table and am using structured references, but you can change to ordinary addressing if you prefer.
TitleList is a named range that includes all or your titles (presumeably you will use this for your dropdown).
For the Helper Column, I have it adjacent to your Names column with the formula:
=IF(OR(A2=TitleList),ROW(),B1)
This creates a unique number for each title.
Then, for your formula, under the dropdown, you can use:
=FILTER(Table3[Names],(Table3[Names]<>G1)* (Table3[Index]=XLOOKUP(G1,Table3[Names],Table3[Index])))
where G1 contains the dropdown
With Column B visible:
Some with O365 do not have the FILTER function. If you do not have the FILTER function, you can use:
=INDEX(Table3[Names],AGGREGATE(15,6,1/(INDEX(Table3[Index],MATCH(G1,Table3[Names],0))=Table3[Index])*ROW(Table3)-ROW(Table3[#Headers]),ROW(INDEX($A:$A,2):INDEX($A:$A,COUNTIF(Table3[Index],INDEX(Table3[Index],MATCH(G1,Table3[Names],0)))))))
EDIT
To return a non-duplicate list of ALL of the names, add ALL to TitleList and use this formula instead.
This formula makes a special case for ALL and filters out the rows that contain a Title
=IF(G1="ALL",UNIQUE(FILTER(Table3[Names],COUNTIF(TitleList,Table3[Names])=0)),FILTER(Table3[Names],(Table3[Names]<>G1)*(Table3[Index]=XLOOKUP(G1,Table3[Names],Table3[Index]))))
.imgur.com/apkHh.png

Related

Excel: Dependant Data Validation Listing values from table with criteria without Macro

I would like to create a data validation field that draws values from a table, but only those values where a corresponding value matches a cell reference: the Month
Ideally this should be done dynamically, rather than having to create multiple named ranges.
I have included an image highlighting the target values I want to pull for January.
Edit: I am exploring using the FILTER formula, but no luck so far.
Edit 2: I got FILTER to work to provide the set of values I'm looking for, but it doesn't seem to want to work as data validation.
=FILTER(tblDate[Date],(tblDate[Month]=E2),"")
As has been commented, the Data Validation list will not accept FILTER, but it will accept other formulae.
In the example, you can set the List validation as:
=OFFSET(B2,MATCH(F2,A2:A18,0)-1,0,COUNTIF(A2:A18,F2))
keying off cell F2 for the value of the month.
NB: This works if the months are ordered (as in the given data). Also note that the List formula doesn't seem to like the Table[] syntax, so you have to put the ranges in as R1C1 format.
Alternatively you can use FILTER() for non-ordered data but put the results in a hidden column (Column H in the example below) on the spreadsheet. It is not as neat, but is more flexible, and allows the Table[] syntax.
eg
H2 = FILTER(Table1[Date],Table1[Month]=F2)
List Range
=$H$2#
(The # uses the result of the FILTER array function from cell $H$2: Hat-tip to #Ike)

Dropdown list with a conditional statement

I have some materials in column B, a few among these are in a Table definition called Material_List. In D49 I am trying to write a conditional statement such that, if the data in B49 already exists in the table definition, then print the header name or else INDIRECT($49). C49 has the independent dropdown list and D49 will be the dependent.
In D49 I have used the following formula within the Data-->Data Validation-->Source=
=IF(MAX((ISNUMBER(MATCH(Material_List;$B49;0))*COLUMN(Material_List)))=0;
INDIRECT($C49);
INDEX(Material_List[#Headers];1;MAX((ISNUMBER(MATCH(Material_List;$B49;0))*
COLUMN(Material_List))))))
with Allow=List. But it says Error "There is a problem with this formula"
When typed the following formula in cell D50 directly, it works well but obviously without dropdown.
=IF(MAX((ISNUMBER(MATCH(Material_List;$B50;0))*COLUMN(Material_List)))=0;
INDIRECT($C50);
INDEX(Material_List[#Headers];1;MAX((ISNUMBER(MATCH(Material_List;$B50;0))*
COLUMN(Material_List))))))
I am trying to build a dropdown list based on the mentioned criteria. could anyone please tell what is wrong with my formula?
I think the main issue with your formula is that you cannot use table references in the data validation.
Don't ask me why. I think it is just an outstanding Excel bug which hasn't been fixed yet. Please see this link for further info: https://exceloffthegrid.com/using-an-excel-table-within-a-data-validation-list/
The best way I have found to work around this is to create a named range which refers to the table references you need ("Material_List" and "Material_List[#Headers]" in your case). Then you can use those named ranges in your data validation instead of the table references directly.
However, I think there are also other issues with your formula. For example, this part:
MATCH(Material_List;$B50;0)
Normally a MATCH would be in the format of:
MATCH(<single value to look for>, <range to look in>, 0)
You appear to have that reversed, meaning that it should always return a #VALUE! error.
Also, I don't think you can use match on a 2D array, so if your "Material_List" table is more than a single column, that would also cause it to return a #VALUE! error.
UPDATE:
The way I would tackle dependent dropdowns would be as follows.
I would create a "Material_List" table similar to below (could be on a hidden sheet):
Then I would create 3 named ranges.
One for the table body range, called "MaterialList_TblRange":
=Material_List
One for the table header range, called "MaterialList_TblHeaderRange":
=Material_List[#Headers]
And one to refer to the dependant dropdown options, called "DropDownOptions" (this is by far the most complicated part):
=INDEX(MaterialList_TblRange,1,MATCH(Sheet1!$B23,MaterialList_TblHeaderRange,0)):INDEX(MaterialList_TblRange,COUNTA(INDEX(MaterialList_TblRange,1,MATCH(Sheet1!$B23,MaterialList_TblHeaderRange,0)):INDEX(MaterialList_TblRange,ROWS(MaterialList_TblRange),MATCH(Sheet1!$B23,MaterialList_TblHeaderRange,0))),MATCH(Sheet1!$B23,MaterialList_TblHeaderRange,0))
I will explain what this is doing in a moment.
The last step is to set up the data validation where we want our lists.
Where we want the master lists to appear, we can simply enter:
=MaterialList_TblHeaderRange
And the defendant dropdown validation can be entered as:
=DropDownOptions
This is the result:
Now back to the long "DropDownOptions" named range formula...
Basically, we use INDEX:INDEX to select the first/last cell in the range we want to use in out dropdown.
The first INDEX:
=INDEX(MaterialList_TblRange,1,MATCH(Sheet1!$B23,MaterialList_TblHeaderRange,0))
Simply selects the first cell from the column whose header matches the selection in our first dropdown.
The second index does the same, except that instead of selecting the first cell in the column, it counts the number of cells that contain text and uses that as the last cell in the range.
This does mean that we mustn't have any gaps in this table, otherwise an option might be missed off the end.
I hope this makes sense.

Filtering a table with any combination of several search criteria

I've made a list of bars for my friends/coworkers and I want to add a tool that allows them to search for bars that match their preferred criteria.
The google sheet can be found here.
I want the user to be able to search based on the criteria they input on the left under "keywords". So this many be anywhere from 1, keyword to all 7 filled out. But I want it to search based on any combination.
I initially started with an INDEX/MATCH formula which only returned a single row.
I landed on the FILTER function after trying different options.
However, this does not ignore blank search terms. Cell D4 on the Search page has the current formula. This will filter by Area, and then Area and Category if both are filled out, but I have yet to figure out how to expand this to the remaining filters.
My current function is the following:
=IFERROR(IF(AND(LEN(B6),LEN(B7)),FILTER(AllInfo,Area=B6,Category=B7),FILTER(AllInfo,Area=B6)),"-")
The filter function does exactly what I want for one search criteria, but my attempts to include any combination of search terms have failed.
I have a number of named data ranges which reference their respective columns on the 'Toronto - BARS' sheet.
Feel free to share this list with any friends living in Toronto!
Edit: removed irrelevant information
The closest I got is the formula below, which requires you to replace the boolean values into "yes" and "no" (or any other string values):
=ArrayFormula(query({AllInfo},"select * "&if(counta(B6:B12)>0,"where ",)&join(" and ","Col"&(match(filter(A6:A12,B6:B12<>""), transpose('Toronto - BARS'!A1:I1),0))&"='"&filter(B6:B12, B6:B12<>"")&"'"),0))
2 improvements that could be made, but I didn't figure it out:
using the column names in the query, instead of column number
parsing the boolean values correctly and add or remove the single quotes accordingly, so it can support the current boolean values / checkboxes
==> I hope someone can pick that up and finish what I couldn't get done.

Extract a Word from String Containing a Specific Multiple Words

"I'm setting up a pivot in excel, and want to extract specific words from a data set of text.
I have tried using the below formula to extract one particular word, but want to nest the multiple formula to extract other words as well
=TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",99)),MAX(1,FIND("Evaluation",SUBSTITUTE(A1," ",REPT(" ",99)))-50),99))
The above formula works but only for one word. I want to create nested formula to search first word or second word or third...
If your goal is to search an array for a a substring, if that substring matches any words in a list, and if so, return the matched substring, as in the post suggested by JvdV, use the formula below, which I have modified.
I recommend, in a different worksheet, add a table with a list of the words you want to find, like this. Highlight the range of cells, including the header, then Home > Format as Table > pick a table style and give it a name. This table's name is "t_WordsToFind" (so I can easily identify it in other functions later). You may want to also put your primary data into a table as well. My go-to name is usually "t_Data". Now, instead of worrying about column numbers/letters, you have the user-friendly column headers you started with which makes reading the formula much easier. Your table ranges will also automatically expand when addtl data is added, so row numbers don't need to be referenced any more either.
If you don't have your data in tables, use this version of the formula, and remember to update your range parameters when data is added. B2 is the first cell to be searched, D2:D4 is the list of words to look for, copy the formula down. I do prefer not to use IFERROR as it includes many different types of errors that I may need to know about, like if I misspelled the function name, for example. If you simply need to have an alternative in the event no matches are return and your function is valid, I recommend IFNA.
IFNA(LOOKUP(1,1/COUNTIF(B2,"*"&$D$2:$D$4&"*"),$D$2:$D$4),"")
If you do use tables for your data and lookup tables (you are very wise) and here is the formula version to use (below). In this example, #[Search This Column] is the the equivalent to B2 and t_WordsToFind[Find This] is the table name and column name of words to look for, but it's much more legible, and doesn't need to be copied down or manually expanded in the future.
IFNA(LOOKUP(1,1/COUNTIF([#[Search This Column]],"*"&t_WordsToFind[Find This]&"*"),t_WordsToFind[Find This]),"")
Even wiser still, assuming this is a perpetual need, would be to use power query/power pivot, but I don't want you to go into TMI overload.
Also, your pivot table range will be nice and easy, "t_Data".

Searching multiple Postcodes in Excel

I have an excel sheet with 8000 records that i would like to search by postcode.
This is my client list and i would like to say search for all clients living in the "EH1","EH2","KY1","SW9" postcodes.
I would like the search to return all the values related to that postcode.
The excel document is laid out like this.
(ID,Name,Surname,Address,Postcode,Telephone Number)
Im a novice at excel spreadsheets so any help on this would be greatly appreciated.
ID Name Surname Address Postcode Telephone number
26584 John Smith 69 Bedford road Eh12 5db 0131225689
Thanks
Edited with quick and dirty method:
If you only need to use this table a few times, then there is a quick and dirty method:
Make a helper column that only includes the first 3 characters of the postcode. You do this via the left function, specifying the postcode column in the first argument, then "3" in the next, to return the first 3 characters. This effectively hides the values you haven't ticked.
You then use the filter section at the top of the column once you have made it a table as stated earlier. In the drop down menu untick "Select all", then tick the values you want to see, i.e. the postcodes you are interested in).
You can then copy the visible cells only via Copy visible cells only if you want to use just that list.
A longer, but more robust method would involve three tables. The first is your data set as it is, with the helper column as discused above included. The second would be a simple single column of all the first three letter codes you are interested in. The third would be an array function modified from this formula:
=index($a$1:$b$7,small(if($a$1:$a$7=$a$10,ROW($a$1:$a$7)),ROW(1:1)),2)
which returns multiple items based on preset criteria, ignoring those that are not specified. I would link to a site explaining this better but I am such a new user I can hardly do anything it seems :(
I suggest you simply use an autofilter on the respective column.
Here is a short tutorial for Excel 2010: AUTOFILTER TUTORIAL
I think an easy way to do this is first make Postcode column first; from Column E to Column A.
Insert a new column in Column A, then use the left function to get the first 3 characters of the postcode: =LEFT(B1,3)
With this, you can use VLOOKUP to search for the postcodes "EH1","EH2","KY1","SW9", and use multiple VLOOKUP formulas to return a column index of everything.
You'll end up with a list of everything for that specific postcode.

Resources