Excel Countif with multiple if requirements - excel

I have an Excel document that has a date column (A) and a column containing strings (B) one one sheet. On another sheet, I am doing calculations. If the cell in column A is between DATE(2012,1,1) and DATE(2012,6,1) AND the same row in column B contains "string" in any part (string) then it should count that row. Google mentioned using SUMPRODUCT but I was only able to get date between to work. Below is the SUMPRODUCT for date between.
=SUMPRODUCT(--('Sheet1'!A:A>=DATE(2012,1,1)),--('Sheet1'!A:A>=DATE(2012,6,1)))
I tried using this for the final value but it is incorrect.
=SUMPRODUCT(--('Sheet1'!A:A>=DATE(2012,1,1)),--('Sheet1'!A:A>=DATE(2012,6,1)),--('Sheet1'!B:B="*"&"string"&"*"))
EDIT: Apparently the above works, but the string must be EQUAL to the value. * is not being recognized as a wildcard.
Thanks.

If you are using whole columns in SUMPRODUCT you must have Excel 2007 or later (otherwise that doesn't work), and you can use wildcards in COUNTIFS
=COUNTIFS('Sheet1'!A:A,">="&DATE(2012,1,1),'Sheet1'!A:A,"<="&DATE(2012,6,1),'Sheet1'!B:B,"*String*")

The issue you're running into is due to the fact that you can't use wildcards in that way in a SUMPRODUCT. A way that you can get around it (assuming you need to use SUMPRODUCT) is to use either SEARCH or FIND to create the necessary array for use in the SUMPRODUCT. Here is an example that has your target string in cell D1 (note that this needs to be entered as an array formula with Ctrl+Shift+Enter):
=SUMPRODUCT(
--(Sheet1!A:A>=DATE(2012,1,1)),
--(Sheet1!A:A<=DATE(2012,6,1)),
IFERROR(IF(SEARCH(D1,Sheet1!B:B)>0,1,0),0))
IFERROR accounts for the non-matches but is an Excel 2007 feature. If you're not using Excel 2007, you can try:
=SUMPRODUCT(
--(Sheet1!A:A>=DATE(2012,1,1)),
--(Sheet1!A:A<=DATE(2012,6,1)),
IF(ISERROR(IF(SEARCH(D1,Sheet1!B:B)>0,1,0)),0,IF(SEARCH(D1,Sheet1!B:B)>0,1,0)))
Also, in your example formula, you'll need switch the sign to <= in the comparison to June :)

Sumproduct does not allow for wildcards. You can search for strings using ISNUMBER(SEARCH("string",range)). The formula is below.
=SUMPRODUCT(--('Sheet1'!A:A>=DATE(2012,1,1)),--('Sheet1'!A:A<=DATE(2012,6,1)),--(ISNUMBER(SEARCH("string",'Sheet1'!B:B))))

What version of Excel are you using? If it is 2007 or later, you can use COUNTIFS; here is a link to the syntax. You may have to use two columns, even using COUNTIFS. On Sheet2, column A should check whether Sheet1, column B contains "string" using the following formula:
=IF(ISERR(FIND("string",'Sheet1'!B1)), FALSE, TRUE)
You will need to replace 'Sheet1'!B1 with whatever cell you need, then drag it down to make it have the same number of rows as your Sheet1, column B. Then you can use COUNTIFS:
=COUNTIFS('Sheet1'!A:A, ">=" DATE(2012,1,1), 'Sheet1'!A:A, ">=" & DATE(2012,6,1), A:A, TRUE.

Related

Multiple VLOOKUPs and a max value

I have a calendar year in Column A and am looking to find a match in column CA. There are multiple matches and within these I am then looking for the match that has "A" in the row next to it. there could be duplicates of this as well and so of those will copy the max value (In column CK). At the moment I have tried some looped vlookup() excel functions but have had no luck. Any help would be appreciated, thanks!
=VLOOKUP(A2&"A", $CA:$CK, 11, FALSE)
Use INDEX/MATCH instead of VLOOKUP().
=INDEX(CK:CK,MATCH(A2&"A",CA:CA&CB:CB,0))
In case of non 365 version of excel, you may need to array entry the formula with CTRL+SHIFT+ENTER.

Add value to different integers in same cell in MS Excel

I have a typical book index in a spreadsheet that goes like this:
I need Excel to recognize the different integers in the same cell and add a constant each one of them.
Let's say the constant is 5
The result should be like this:
I couldn't get excel to recognize the different values in a cell.
My two cents, assuming Excel ms365:
Formula in B1:
=BYROW(A1:A3,LAMBDA(a,LET(X,TEXTSPLIT(a,", "),TEXTJOIN(", ",,IFERROR(X+C1,X)))))
Or, if no access to TEXTSPLIT(), then use:
=BYROW(A1:A3,LAMBDA(a,LET(X,FILTERXML("<t><s>"&SUBSTITUTE(a,",","</s><s>")&"</s></t>","//s"),TEXTJOIN(", ",,IFERROR(X+C1,X)))))
Or, if no access to BYROW(), you'd have to drag the following:
=LET(X,FILTERXML("<t><s>"&SUBSTITUTE(A1,",","</s><s>")&"</s></t>","//s"),TEXTJOIN(", ",,IFERROR(X+C$1,X)))
Not sure if this could be done smoothly and without using long and complex formulas.
Why don't you try to split the cell into multiple columns (Data > Data Tools > Text To Columns > Delimited and select Comma as delimiter). Once you have all different values is separate columns, it would be easy to apply formulas and add the constant.
After that, you could use CONCATENATE formula to merge texts and numbers back to single value in a single column.
Hope this helps.
I would separate the text and each value into separate cells, then use & to combine into the format you want, something like so:
=A1&", "&B1+G1&", "&C1+G1&", "&D1+G1
where A1 contains "Trauma" and B1 contains 15, C1 contains 17 and D1 contains 25. G1 holds the constant 5.
See
This is what I have tried,
Formula Applicable To Only O365 Beta Channel (Insiders).
• Formula used in cell B1
=TEXTJOIN(", ",,TEXTBEFORE(A1,", ",1),TEXTSPLIT(TEXTAFTER(A1,", ",1),", ")+5)
Or, if you are not using the above Excel Version, but using either Excel 2019, 2021 or Regular O365, then,
• Formula used in cell B1
=TEXTJOIN(", ",,LEFT(A1,FIND(",",A1)-1),IFERROR(
FILTERXML("<a><b>"&SUBSTITUTE(A1,", ","</b><b>")&"</b></a>","//b")+5,""))
Edit
One improvised approach:
=TEXTJOIN(", ",,TEXTBEFORE(A1,", ",1),IFERROR(TEXTSPLIT(A1,", ")+5,""))
You can also accomplish this task quite easily with Power Query.

Formula to extract usernames of instagram links in Excel sheet

I have a list of instagram url's in a excel sheet and i need to extract their user names into another column using a formula.
I have used this formula but it's incomplete and does not work as i need.
=RIGHT(C111,FIND("/",C111))
For example, how can i extract the user name stack_test from the url https://www.instagram.com/stack_test/ which is in a excel sheet.
If you need user names only then you can do it without formula.
You can use Text to Column (Short Cut:Alt + D then E).
Select Delimited, In delemeters dialog select Other and use /.
EDIT FILTERXML XPATH argument changed. After doing some research, discovered you can specify "next to last" node, instead of using the LOOKUP function.
If your version of Excel has the FILTERXML function, you can use:
=FILTERXML("<t><s>"&SUBSTITUTE(A1,"/","</s><s>")&"</s></t>","//s[last()-1]")
If you have an older version of Excel, you can use:
=TRIM(RIGHT(SUBSTITUTE(IF(RIGHT(A1,1)="/",LEFT(A1,LEN(A1)-1),A1),"/",REPT(" ",99)),99))
This works if there are exactly two / in each row, and the username is between them.
Type some_text/username/some_other_text in cell A1.
I broke down the formula in multiple cells to make it more readable, but you can make a one-cell formula:
B1: =FIND("/",A1)
C1: =FIND("/",A1,B1+1)
D1: =MID(A1,B1+1,C1-B1-1) . This will show username
If there can be multiple / and you only need the last two, it is more complicated. You might want to have a look:
here and here (non-VBA examples)
or here (VBA)
Try:
=MID(A1,FIND("com/",A1)+4,(SEARCH("^^",SUBSTITUTE(A1,"/","^^",LEN(A1)-LEN(SUBSTITUTE(A1,"/",""))))-(FIND("com/",A1)+4)))

Excel array formula with wildcard

I have an array formula that refers to a drop down cell ($AG$7) to determine which cells to evaluate. This works well, however, I need to include an additional item in the drop down which is "All".
When this is selected, I want the array formula to use "*" to return all instances from the array, but i can't get it to work.
This is the formula I'm currently using;
={SUM(IF((tblSkillsMatrix[Role]=[#Role])*(INDIRECT("tblSkillsMatrix["&V$2&"]")=$AG$7),1,0))}
I've tried using
={SUM(IF((tblSkillsMatrix[Role]=[#Role])*(INDIRECT("tblSkillsMatrix["&V$2&"]")="*"&$AG$7),1,0))}
and
={SUM(IF((tblSkillsMatrix[Role]=[#Role])*(INDIRECT("tblSkillsMatrix["&V$2&"]")="*"&$AG$7&"*"),1,0))}
But these don't work.
Does anybody have any ideas?
Thanks
A explicit = comparison cannot use wildcards. COUTIFS and SUMIFS can. As far as I see, you want to count only (conditional sum 1 and 0).
Problem is, COUTIFS and SUMIFS will not deal with INDIRECT ranges. But INDIRECT can and should (because of its volatile bahavior) often replaced by INDEX- MATCH.
So:
=COUNTIFS(tblSkillsMatrix[role],[#role],INDEX(tblSkillsMatrix,,MATCH($V$2,tblSkillsMatrix[#Headers],0)),"*"&$AG$7)
If $AG$7 is empty then it counts independent of the column named in $V$2.
Btw.: Within a table (ListObject) this needs not be entered as a array formula.
This is not 100% replacement of your formula since it not works if $V$2 is empty and so no table column title is given. Your formula will then look at all columns but this is not possible using COUNTIFS where each additional range must have the same number of columns as the criteria_range1 argument. So if $V$2 shall also can be empty, then this will not work.
If so then you could use
{=SUM((tblSkillsMatrix[role]=[#role])*(LEFT(INDIRECT("tblSkillsMatrix["&$V$2&"]"),LEN($AG$7))=$AG$7))}
Advantage: both $V$2 and $AG$7can be empty.
Disadvantage: Volatile behavior of INDIRECT and this formula then must be a array formula even in a ListObject-table. It must be confirmed using Ctrl+Shift+Enter.

Microsoft Excel - for each unique value in column A, return max value from column C and the corresponding value from B

using a formula, I'm looking to get the max of column C for each unique value in column A then I'd like to also return the corresponding value from column B to the max of column C. the output should be a summary of the data as in the second screen capture. I've tried pivot tables, conditional formatting and the help in this link with no luck Get the maximum values of column B per each distinct value of column A
original data
desired result
Is this possible with formulas?
So for the Max number use the AGGREGATE() Function:
=AGGREGATE(14,6,$C$2:INDEX(C:C,MATCH(1E+99,C:C))/($A$2:INDEX(A:A,MATCH(1E+99,C:C))=I2),1)
Then to find the Capacity a simple SUMIF():
=SUMIFS(B:B,A:A,I2,C:C,K2)
The AGGREGATE() Function was introduced in Excel 2010.
For other versions, the less robust Array Formula MAX(IF()) will work in place of the AGGREGATE:
=MAX(IF($A$2:INDEX(A:A,MATCH(1E+99,C:C))=I2,$C$2:INDEX(C:C,MATCH(1E+99,C:C))))
Being an Array Formula it must be confirmed with Ctrl-Shift-Enter when exiting Edit mode. When done correctly Excel will automatically put {} around the formula to denote an array formula.
Another, If you have the latest Office 365 or using the online app the following non CSE MAXIFS() will work also:
=MAXIFS($C$2:INDEX(C:C,MATCH(1E+99,C:C)),$A$2:INDEX(A:A,MATCH(1E+99,C:C)),I2)
These two are not as robust as the AGGREGATE() in that they will break if there are errors in the data. AGGREGATE() will ignore them.
Here's another option using Array formula, in a Table. I didn't do this starting at A1 in my sheet, so the image has my cell/row IDs to assist!
Cell M17: =IFNA(INDEX([Host], MATCH(0, COUNTIF($M$16:M16, [Host]), 0)),"Unknown") +Ctrl+Shift+Enter
Cell N17: =MAX(IF([Host]=[#UniqueHost],[Duration])) +Ctrl+Shift+Enter
Cell O17: =IFNA(INDEX([Capacity],MATCH([#UniqueHost]&[#MaxDuration],[Host]&[Duration],0)),0) +Ctrl+Shift+Enter

Resources