Excel Countifs - Search Text in String - excel

I have a column (let's say B1) in an Excel form that shows some products like this:
Sand Systems
Gas Systems
Blenders
Other
Other 2
Other 3
Other 4
I need to count the rows that doesn't contain the text "Other #" (# being a number), in other words, "Sand Systems", "Gas Systems", "Blenders" and "Other" = 4.
The solution so far was using an auxiliary column with the formula =SEARCH , but how to make it ignore the "Other" cell and accept "Other #"? Additionally, I wouldn't like to use an auxiliary column, but a cell with the =COUNTIF formula. Any advice?

One approach is something like:
=COUNTIF(A1:A7,"<>" & "Other *")
This returns 4, which is the expected result?
Using the whole column reference will return the incorrect result, just FYI. If you're dead set on using whole column references use Ron Rosenfeld's formula:
=COUNTA(A:A)-COUNTIF(A:A,"Other *")

=COUNTA(A:A)-COUNTIF(A:A,"Other *")
Count them all, then subtract the one's that contain Other followed by space and anything else.

Related

excel: if cell contains multiple criteria then return multiple criteria, nestled?

I have 4 criteria lists that look like this:
A B
Name Category
Name Category
Name Category
And a MasterList like this:
A B
stuffNAME Category
NAMEstuff Category
NAME Category
I would like to know if there is a formula that can search through each criteria list based on the MasterlistA column for "NAME" and return the appropriate "Category" in MasterlistB.
As an example:
I'm looking to return MasterlistB based on MasterlistA
Criteria List:
A B
NBC NBCU
Disney ABC
Masterlist:
A B
NYC NBC 20998 NBCU
NJ2987 NBC NBCU
Disney Florida99 ABC
I'm simplifying, but in reality the criteria lists all refer to different masterlist columns as well. Trying to get the matching/searching part down first.
Given a setup as shown in #ScottCraner 's answer:
In cell E1 and copied down:
=IFERROR(LOOKUP(1,1/COUNTIF(D1,"*"&$A$1:$A$2&"*"),$B$1:$B$2),"No Match")
This is a regular formula and does not require array entry.
You can do this using VLOOKUP, nested with the IFERROR statement.
I am assuming each table is starting on A1, in sheets called Sheet1, Sheet2, Sheet3, and Sheet4. You may need to adjust references to point to appropriate tables.
The basic formula to find the category which matches your name, is simply [assuming your search term is on a new sheet on A1, let's say Sheet5, with the rest of your final data table]:
=VLOOKUP(A1,'Sheet1'!A:B,2,0)
This simply takes the value in A1 [the search term], tries to find it in column A of sheet 1, and if it does find it, takes the first matching row, and returns the value on the 2nd column in [column B, with the category].
If that fails, you simply put that inside of IFERROR, which attempts to calculate something, and if it creates an error, returns something else, like so:
=IFERROR(VLOOKUP(A1,'Sheet1'!A:B,2,0),"NO MATCH FOUND")
Now to use the IFERRORS to first attempt to find a match on Sheet1, then Sheet2, etc., put the following:
=IFERROR(VLOOKUP(A1,'Sheet1'!A:B,2,0),IFERROR(VLOOKUP(A1,'Sheet2'!A:B,2,0),IFERROR(VLOOKUP(A1,'Sheet3'!A:B,2,0),VLOOKUP(A1,'Sheet4'!A:B,2,0))))
To search for only a partial match, you can use the following:
=VLOOKUP("*"&A1&"*",'Sheet1'!A:B,2,0)
The "*" act like wildcards, and if they are included in front of and behind your search term [in this case, A1], then anything that contains your search term, regardless of its position in a cell, will be considered a match. You can replace A1 in all of my above formulas with this revised wildcard match to check for partial matches in any of your sheets.
To search a list of items, which exactly match a part of your search term
You could probably do this with an array formula, but because you have multiple data tables, I think the easiest solution is to use a helper column next to each of those tables, to create a unique ID which actually matches to your Master List. ie:
On Sheet1 [and all other category sheets], insert a new column in between A & B; this column will trace back from column A, to match a Name from your Master List on Sheet5, like so [starting in B1 & copied down]:
=VLOOKUP("*"&A1&"*", 'Sheet5'!A:A, 1, 0)
Your revised formula in your master sheet would now look like this:
=IFERROR(VLOOKUP(A1,'Sheet1'!B:C,2,0),IFERROR(VLOOKUP(A1,'Sheet2'!B:C,2,0),IFERROR(VLOOKUP(A1,'Sheet3'!B:C,2,0),VLOOKUP(A1,'Sheet4'!B:C,2,0))))
Rather than placing the four lists side-by-side like:
Stack them on top of each other like:
The its as simple as:
=VLOOKUP("David",A1:B12,2)
So here is the basic formula to get what you want:
=INDEX($B$1:$B$2,AGGREGATE(15,6,ROW($1:$2)/(ISNUMBER(SEARCH("*" & $A$1:$A$2 & "*",D1))),1))
if you have 2010 or later. If you have 2007 and earlier than you will need to use the following array formula:
=INDEX($B$1:$B$2,SMALL(IF(ISNUMBER(SEARCH("*" & $A$1:$A$2 & "*",D1)),ROW($1:$2)),1))
It being an array formula it must be confirmed with Ctrl-Shift-Enter.
In the picture, the first formula is Column F, the second in Column E
You will need to add nested IFERROR() Functions for the various sheets.
=IFERROR(INDEX(Sheet1!$B$1:$B$2,AGGREGATE(15,6,ROW($1:$2)/(ISNUMBER(SEARCH("*" & Sheet1!$A$1:$A$2 & "*",A1))),1)),IFERROR(INDEX(Sheet2!$B$1:$B$2,AGGREGATE(15,6,ROW($1:$2)/(ISNUMBER(SEARCH("*" & Sheet2!$A$1:$A$2 & "*",A1))),1)),IFERROR(INDEX(Sheet3!$B$1:$B$2,AGGREGATE(15,6,ROW($1:$2)/(ISNUMBER(SEARCH("*" & Sheet3!$A$1:$A$2 & "*",A1))),1)),IFERROR(INDEX(Sheet4!$B$1:$B$2,AGGREGATE(15,6,ROW($1:$2)/(ISNUMBER(SEARCH("*" & Sheet4!$A$1:$A$2 & "*",A1))),1)),"NOT HERE"))))

Excel, append one range to the end of another in one column

I have two columns of data in Excel. I would like to add a third column which combines the first and second. How can I do this with a formula such that I can add or remove data from columns A and B without ever having to touch column C?
Column A Column B Column C
Bob Mary Bob
Joe Melissa Joe
Jim Jackie Jim
Mary
Melissa
Jackie
The question explicit mention Microsoft Office Excel but I think would be good to add that if you are using Google Sheets a simpler solution is to use the curly brackets function/operator as mentioned by Lake at https://stackoverflow.com/a/14151000/1802726.
Here is a simple solution using FILTERXML and TEXTJOIN that can append MULTIPLE RANGES OF ANY SIZE, ARRAY FORMULAS AND REGULAR FORMULAS. Just replace YOUR_RANGES with the ranges or dynamic arrays you wish to join:
Simple version that ignores empty cells:
=FILTERXML("<A><B>" & TEXTJOIN("</B><B>",TRUE,YOUR_RANGES) & "</B></A>", "//B")
This one includes empty cells:
=IFERROR(FILTERXML("<A><B>" & TEXTJOIN("</B><B>",FALSE,YOUR_RANGE) & "</B></A>", "//B"), "")
If your input data contains the "<" character, the formulas above will return an error, so use this one instead:
=IFERROR(SUBSTITUTE(FILTERXML("<A><B>" & SUBSTITUTE(SUBSTITUTE(TEXTJOIN("ΨΨ",FALSE,YOUR_RANGE),"<","ЉЉ"),"ΨΨ","</B><B>")&"</B></A>","//B"),"ЉЉ","<"),"")
Note: you can change the FALSE to TRUE to ignore empty cells.
Note 2: You can replace the characters ЉЉ and ΨΨ by any character(s). I used these specific characters because it is very unlikely that your input data will contain ЉЉ or ΨΨ, which would cause errors.
NOTES:
Tested on:
Excel 365
EXAMPLE:
Using the simple version of the formula:
=FILTERXML("<A><B>" & TEXTJOIN("</B><B>",TRUE,A1:A3,B1:B3,C1:C3) & "</B></A>", "//B")
As a result you will get a dynamic array with the joined/appended ranges:
You can then apply any dynamic array formula (like UNIQUE) to the result.
HOW THIS WORKS:
The JOINTEXT function grabs your ranges and joins them as a text with the delimiter "</ B >< B >". Then, after adding "< A >< B >" to the beginning and "</ B ></ A >" to the end, we have an XML formatted text:
<A><B>1</B><B>2</B><B>3</B><B>A</B><B>B</B><B>C</B><B>!</B><B>#</B><B>#</B></A>
Finally, the FILTERXML will separate the tags into a dynamic array which will be the joined/appended ranges.
Enter the following formula into cell C1
=IF(ROW()>COUNTA(A:B),"",IF(ROW()<=COUNTA(A:A),INDEX(A:A,ROW()),INDEX(B:B,ROW()-COUNTA(B:B))))
Then copy down as far as you need.
Here's a nice way of interleaving the two rows.
In other words, turning this:
A X
B Y
C Z
into this:
X
A
Y
B
Z
C
Say the above table is in columns one and two, you'd do:
=IF(MOD(ROW(),2)=0,INDIRECT(ADDRESS(INT(ROW()/2), 1)),
INDIRECT(ADDRESS(INT(ROW()/2)+1, 2)))
Explanation
Let's break that down a little. The first part is MOD(ROW(), 2) which returns a zero if the current row is even, and a one if it's odd.
So the IF goes FALSE/TRUE/FALSE/TRUE as we go down the column.
Next, the ADDRESS(INT(ROW()/2), 1) returns us a string representation of the address of the cell at column 1 and at half the current row. (Rounded down). This piece on its own looks like:
#VALUE!
$A$1
$A$1
$A$2
$A$2
$A$3
$A$3
(That first #VALUE error is because 1/2 = 0.5 which rounds down to zero. There's no row zero!)
The INDIRECT function returns whatever value is found at that address.
The rest is pretty clear.
NOTE: There may be a slicker way than using INDIRECT and ADDRESS. Suggestions welcome.

Index/Match with multiple possible answers?

There's a question about how to return some info in Excel, COUNTIFS for VLOOKUP. from #THATNewbie.
Here's a quick summary:
They have this table:
Report Name User Name Report Category
Report 1 John Smith Sales
Report 1 Jack Black Sales
Report 1 Connie Rae Sales
Report 1 Brain Bonds Sales
Report 2 John Smith Sales
Report 2 Connie Rae Sales
Report 3 Jack Black Inventory
And they would like to return the "Report Name" based on User Name and Report Category.
My first thought was just to use Index/Match (as an Array)...however, I realize that if I use "John Smith" and "Sales" to look up the Report Name, there's two possible outcomes: Report 1 and Report 2. Index/Match will always return Report1 (or whatever comes first, going down that column).
My question is: Is there a way to write the Index/Match formula to check if it's already found Report1 and therefore to go to the next match (Report2)?
Here's a screenshot to help visualize. As you can see, the Index/Match correctly finds Report1 in C12, but also in C13. Can you have the formula "look above" and if it's the answer that it WOULD return, to skip that and look for the next? Does that make sense?
You can try something like this:
=INDEX(Report_Name,MATCH(The_User&":"&The_Category,User_Name&":"&Report_Category,0))
The idea is to concatenate user name and report category into a single search item. (I added a colon char as a delimiter; this was optional and could possibly be omitted.) Then use MATCH to get the index of the matching item, and INDEX to convert the index to a specific report.
Hope that helps.
Unfortunately there is no way (to my knowledge) to do this. You will have to add some sort of unique identifier to each row, or a value that helps define it uniquely. For example, you could add a new column with this function
=COUNTIFS($B$2:$B2, "=" & $B2, $C$2:$C2, "=" & $C2)
What this will do is count the total number times that that specific grouping has shown up, and effectively act as a pseudo ID for it. Then you can add that item to your Index/Match
Then in the second table you showed in the image, you just repeat the count function in the match, so you will have
=INDEX($A$2:$A$8, MATCH(1, (A12 = $B$2:$B$8) * (B12 = $C$2:$C$8) * (COUNTIFS($A$12:$A12, "=" & $A2, $B$2:$B2, "=" & $B2) = $D$2:$D8), 0))
This is an array entered forumla
My question is: Is there a way to write the Index/Match formula to
check if it's already found Report1 and therefore to go to the next
match (Report2)?
Yes, but a simpler way it can be done is using index & small.
Index & small
Need to CTRL+SHIFT+ENTER. Copy down for remaining rows.
{=INDEX($A$2:$A$16,SMALL(IF(A19=$B$2:$B$16,IF(B19=$C$2:$C$16,ROW($B$2:$B$16)-ROW($B$2)+1),""),ROW(B2)-1))}
Where A19 & B19 contain cells for search criteria.
Using Index & Match;
This could possibly be simplified but shows the steps.
Add another column alongside the search criteria area & change the formulas as below.
Need to CTRL+SHIFT+ENTER.
Column C (Report Name);
Following for the first row or search criteria item only
{=INDEX($A$1:$A$16,MATCH(A21&B21,$B$2:$B$16&$C$2:$C$16,0)+ROW(A2)-1)}
Copy following down for the remaining rows items.
{=INDEX($A$1:$A$16,MATCH(A22&B22,INDIRECT(CONCATENATE("B",E22,":","B16"))&INDIRECT(CONCATENATE("C",E22,":","C16")),0)+ROW(INDIRECT(CONCATENATE("B",E22)))-1,1)}
Column E - helper column. Helper column returns the start of the next row.
First row item is N/A.
Following for 2nd or search criteria item only.
{=MATCH(A22&B22,$B$2:$B$16&$C$2:$C$16,0)+ROW(A2)}
Following copy down for remaining rows.
{=MATCH(A23&B23,INDIRECT(CONCATENATE("B",E22,":","B16"))&INDIRECT(CONCATENATE("C",E22,":","C16")),0)+ROW(INDIRECT(CONCATENATE("F",E22)))}
This however does assume the search criteria is the same, unlike the other question referred to. If search criteria is different or more complex refer to
COUNTIFS for VLOOKUP

SumProduct, doesn't return me text and number. (Only Number)

At first thanks to answer)) (It's important for me :p )
I have a number in A3.
When there is this number in column A (Sheet1), per exemple A7 then it will take the value of the cell B7.
=SOMMEPROD(('Sheet1'!A3:A34=Sheet1!A3)*('Sheet1'!B3:B34))
I use SOMMEPROD, it's working but only with number, and sometimes I have text and number in my cell (column B).
I already changed the format of the cell but doesn't work.
Thanks a lot)))
I think you are saying that some of the values in column B are expressed as text, not as a number, probably because they were imported from another source.
if that is the case: First, convert column B into numbers, Then, use sumproduct.
For example, FIRST convert text to values:
in C3 you would enter
=value(b3)
Then copy that down to from C3 to C34.
Then
=SOMMEPROD(('Sheet1'!A3:A34=Sheet1!A3)*('Sheet1'!C3:C34))
should have the desired effect.
Note that you sometime get #N/A errors with the "value" function, for example if there are unexpected spaces. To be safe, rather than using value alone, try this:
= iferror(value(B3),0)
or to be more creative you can try:
= iferror(value(substitute(B3," ","")),0) ' deletes all spaces
= iferror(value(substitute(substitute(b3,char(160),"")," ","")),0)
'deletes all spaces and "nonbreaking spaces" copied from a web page
It depends on what you're trying to use SumProduct for. There's two main reasons this function shows up. Those are:
To sum the product of two ranges.
To sum a range of numbers that meet multiple criteria. This relies on that True = 1 and False = 0 so when want to find the combined weight of blue dogs in some cells, your formula might look like =SUMPRODUCT(1*($A$1:$A$50 = "Blue"), 1*($B$1:$B$50 = "Dog"), $C$1:$C$50). Note the 1* which guarantees the formula will know how to multiply the results. After all, True and False don't multiply. Their binary representations (1 and 0) though, do.
NB though that people also sometimes remember it as a lookup formula because of the second use, and therefore expect to be able to get text back. Such approaches are an easy misunderstanding to end up with, but really there you want to use an INDEX(<Result Array>,MATCH(1,INDEX(1 * (FIRST CONDITION) * (SECOND CONDITION) * (AND SO ON),,),0). This approach basically gives you an array formula without CTRL-SHIFT-ENTER (it's not faster, but because the condition is in an index formula, it works), and your conditions can be arbitrary (the same way as for sumproduct). But it'll give you the FIRST result, not the sum of all of them.
Hope that helps.
Edit: Crossed my mind, you might be expecting A1 to contain Erp and B1 to contain 54, and in C1 you want Erp54. This doesn't even need a function - just the & operator, which joins two strings together - so in C1, you'd just put =A1 & B1. And you're done.

adding wildcard to look up formula?

I am using the following formula as part of a multi result look up function. I have several of these formulas posted into one row each beneath the other, so if I type catering into cell K22 on sheet 1 my formula then looks up that matching word from column b on sheet 2 and produces the name in column a. The formula also includes duplicating this lookup a few times to fetch other values from other columns with the same matching result.
so for instance my columns on sheet 2 look like:
Name Description Location Number
Amy hotel london 1
Dave hotels manchester 2
Mike catering Birmingham 3
What I want to do is to use wild cards around my cell K22 in this formula to show if the descripion word I type in is like hotel; i.e. hotels, hote ... etc then find the result?
...
I know this can be done using index match but can I use them with the following code I have? at the moment this is an array formula but I get no result when I try to do it like this. can someone show me where I am going wrong, tanks
=IF(ISERROR(INDEX(Sheet2!$A$1:$D$7,SMALL(IF(Sheet2!$B$1:$B$7="*"&Sheet1!$K$22&"*",ROW($B$1:$B$7)),ROW(1:1)),1)),"",INDEX(Sheet2!$A$1:$D$7,SMALL(IF(Sheet2!$B$1:$B$7="*"&Sheet1!$K$22&"*",ROW($B$1:$B$7)),ROW(1:1)),1)) & " - " &IF(ISERROR(INDEX(Sheet2!$A$1:$D$7,SMALL(IF(Sheet2!$B$1:$B$7="*"&Sheet1!$K$22&"*",ROW($B$1:$B$7)),ROW(1:1)),3)),"",INDEX(Sheet2!$A$1:$D$7,SMALL(IF(Sheet2!$B$1:$B$7="*"&Sheet1!$K$22&"*",ROW($B$1:$B$7)),ROW(1:1)),3)) & " - " &IF(ISERROR(INDEX(Sheet2!$A$1:$D$7,SMALL(IF(Sheet2!$B$1:$B$7="*"&Sheet1!$K$22&"*",ROW($B$1:$B$7)),ROW(1:1)),4)),"",INDEX(Sheet2!$A$1:$D$7,SMALL(IF(Sheet2!$B$1:$B$7="*"&Sheet1!$K$22&"*",ROW($B$1:$B$7)),ROW(1:1)),4
Although you can use wildcards in the lookup value within a MATCH function (and in other contexts), you can't use them here. When using wildcards with a direct comparison with = like you have, i.e.
Sheet2!$B$1:$B$7="*"&Sheet1!$K$22&"*"
the * is interpreted as a literal asterisk not a wildcard
Replace all instance of the above with this
ISNUMBER(SEARCH(Sheet1!$K$22,Sheet2!$B$1:$B$7))

Resources