Dynamic OR criteria for SUMIFS - excel

I have a formula like below
=SUM(SUMIFS('Sheet1'!$AK:$AK,'Sheet1'!$AL:$AL,"<=0",'Sheet1'!$N:$N,C2))
I want the C2 to be a dynamic multiple criteria OR field which might range from 1 to 4 criteria.
If it would have been static the formula would be something like below
=SUM(SUMIFS('Sheet1'!$AK:$AK,'Sheet1'!$AL:$AL,"<=0",'Sheet1'!$N:$N,{"262","261","200"}))
How do I do it ? I can't get it to work with {"262","261","200"} as value in C2.
The below doesn't work either after having different values in C2,C3,C4
=SUM(SUMIFS('Sheet1'!$AK:$AK,'Sheet1'!$AL:$AL,"<=0",'Sheet1'!$N:$N,{C2,C3,C4}))

Try the following:
=SUM(SUMIFS(Sheet1!$AK:$AK,Sheet1!$AL:$AL,"<=0",Sheet1!$N:$N,FILTERXML("<t><s>" & SUBSTITUTE(C2, ",", "</s><s>") & "</s></t>", "//s")))
Credit to Vafā Sarmast for splitting to array technique.
It seems, from using evaluate formula, that the numbers end up being enclosed in <s> tags, which are then used via xpath of //s, to return all matching items as a list i.e. the numbers as an array. To insert the tags substitute is used on the existing delimiter along with concatenation (& "</s></t>"). At least, that is my understanding.
Enter with Ctrl + Shift + Enter as array formula.
Values go in as comma separated in C2
Info:
FILTERXML

Try the following formula. SUMIFS() supports multiple criteria so you can user C2, C3, C4 as criteria.
=SUM(SUMIFS(Sheet1!$AK:$AK,Sheet1!$AL:$AL,"<=0",Sheet1!$N:$N,C2,Sheet1!$N:$N,C3,Sheet1!$N:$N,C4))

Related

Excel concatenate function with multiple conditions

I have the following in my first 3 columns of my sheet in excel:
Results table. C3 is where I want the concatenation done
I also have the following table:
Now I am trying to use concatenate to retrieve the items from table 69 using the following conditions:
Spec = the value in B1 (Yellow in first photo)
Slot = each of the values in column A (A2:A18)
this is the formula I have in C2:
=CONCATENATE(IF(AND(Table69[Spec]=$B$1;Table69[Slot]=A2);Table69[Item];"")& ",")
Can anybody help me with this as this formula for the moment is returning as if there was no values?
Try using commas instead of semicolons. Once you do that your formula should return "Icon of the Silver Crescent,".
As a side note, the ampersand "&" sign will do the same thing as the concatenate formula. You are adding a comma at the end of your function.
I found an answer using Text join.
Thank you all that took the time.
=TEXTJOIN(", ";TRUE;IF((Table69[Spec]=$B$1)*(Table69[Slot]=A2);Table69[Item];""))

Excel Formula - Criteria To Concatenate multiple cells by matching source cell

I am Looking to concatenates multiple cells into one by Index-matching the criteria
The below formula is not pulling in all the required UPCs against the specified criteria
=INDEX($B:$B,MATCH($D:$D,$A:$A,0))
I would like the end result to look like COL E2 in the below image with semi-colons in between every value ;
Any help here would be much appreciated.
If you have Office365 then use TEXTJOIN() with FILTER() function.
=TEXTJOIN(";",TRUE,FILTER($B$2:$B$15,$A$2:$A$15=D2))
Edit: Assuming you don't have access to O365 dynamic formulas. Then try below array formula.
=TEXTJOIN(";",TRUE,IF($A$2:$A$15=D2,$B$2:$B$15,""))
Press CTRL+SHIFT+ENTER to evaluate the formula as it is an array formula.
An alternative approach using the CONCAT function:
=CONCAT(FILTER(B:B, A:A=D2)&";")
Explanation:
The FILTER logic is just like Harun24HR suggested. Creating an array of all the values in B where the value in A is equal to D2.
The & operator works on each element in the array and adds a delimiter ";" to each value.
Finally, the CONCAT function combines all of the elements in the array into a single string.

Extracting strings between specific characters in excel and separating them with a comma

Is there a way to extract multiple strings between specific characters in excel and separating them with a comma.
For example:
I am thankful for every help!
The following requires a version of Excel O365 that supports dynamic arrays and the LET function.
If I understand correctly you are looking for something like this.
This formula will list all the positions of all [ in the string using dynamic array functions.
=LET(x,$B$2,
y, SEQUENCE(LEN(x)),
raw, IF(MID(x,y,1)="[",y,""),
filtered, FILTER(raw,raw<>"",""),
filtered)
LET allows you to set names within a formula using parameter pairs. The first is the name; the second is the value of the name. The last parameter is the value returned. In this case, x is set to cell B2. y is set to the array listing the numbers from 1 to the length of x using the dynamic array function SEQUENCE. raw is a list that shows the value of y if that position is [, otherwise it is blank. filtered uses the FILTER function to remove all of the blank rows. filtered is the last argument of the LET function so that is what is returned. If this formula is entered into cell A4 then A4 will show 1, A5 will show 14 and A6 will show 28.
If you then enter a similar formula in B4 replacing [ with ] then the result is {7,21,35} in cells B4, B5 and B6.
Finally, in cell B2 you can enter =TEXTJOIN(", ",TRUE,MID(A2,A4#+1,B4#-A4#-1)). This will return the result you are looking for.
If you are unfamiliar with dynamic arrays, A4# indicates an entire dynamic array starting in cell A4. In this case, it is the same as A4:A6.
More information on Dynamic Arrays
More information on LET
You can't do it with only formulas in Excel 2007. You need VBA UDF then. With Excel O365 having dynamic formula access, this can be done like:
=TEXTJOIN(", ",TRUE,TRIM(LEFT(FILTERXML("<t><s>"&SUBSTITUTE(SUBSTITUTE(A1,"]",REPT(" ",100)),"[","</s><s> ")&"</s></t>","//s[starts-with(., ' ')]"),100)))
Considering that you are using too old version of excel which lacks dynamic array functions and besides too many other useful functions, You may probably have to do a long workaround here.
First using substitute and len You have to find out number of such square parenthesis in each of the row. Thereafter you have to work out the formula of max of such numbers.
Do it like this
Assuming your text-values in A2 for a max of 4 occurrences enter the following formula in B2
=SUBSTITUTE(TRIM(REPLACE(LEFT(A2,FIND("]",A2&"]")-1),1,FIND("[",A2&"["),"")&" "&REPLACE(LEFT(A2,FIND("#",SUBSTITUTE(A2&REPT("]",2),"]","#",2))-1),1,FIND("#",SUBSTITUTE(A2&REPT("[",2),"[","#",2)),"")&" "&REPLACE(LEFT(A2,FIND("#",SUBSTITUTE(A2&REPT("]",3),"]","#",3))-1),1,FIND("#",SUBSTITUTE(A2&REPT("[",3),"[","#",3)),"")&" "&REPLACE(LEFT(A2,FIND("#",SUBSTITUTE(A2&REPT("]",4),"]","#",4))-1),1,FIND("#",SUBSTITUTE(A2&REPT("[",4),"[","#",4)),"")), " ", ", ")
Let's say this is the text in A2
I have a text [123] and some more [4523] and also [552222] how to extract [22]?
This will create a output of 123,4523,552222,22 in B2
There is no "extraction" in your question, just removal. The formula below replaces the unwanted characters with "", thereby removing them. Please try it.
=SUBSTITUTE(SUBSTITUTE(A2,"[",""),"]","")

How do i check a cell for a list of strings in Excel?

So I have two lists in excel.
The first list is made up of large strings.
The second list is made up of smaller strings.
I need to check the first list, to see if any of the strings in the second list are contained in each cell.
Is there an excel formula for that?
I can look up each one individually with an isnumber formula
=IF(ISNUMBER(SEARCH("*dog*",A1)),"dog","No Dog")
but I have a few hundred to go through, so if I can do something like a VLOOKUP that would be better.
For example if one cell in 1st list contacts "Bored" and the second list contains the first 4 letters of the alphabet (a,b,c,d) then a "true" value" of some such would be fine. Then I'd want to check the second cell in the list, and if that was "Tempest" than a "False" value is what I would need, and so on and so on down the list.
With phrases in column A and keywords in column B, in D1 enter the array formula:
=LEN(TEXTJOIN(",",TRUE,IF(ISNUMBER(SEARCH(B$1:B$10,A1)),B$1:B$10,"")))>0
Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key. If this is done correctly, the formula will appear with curly braces around it in the Formula Bar.
NOTE:
the core of this formula:
=TEXTJOIN(",",TRUE,IF(ISNUMBER(SEARCH(B$1:B$10,A1)),B$1:B$10,""))
actually lists the key words:
EDIT#1:
If your version of Excel does not support TEXTJOIN() then use this array formula:
=LEN(IFERROR(INDEX(B:B,MATCH(TRUE,ISNUMBER(SEARCH($B$1:$B$10,A1)),0)),""))>0
or this non-array formula:
=SUMPRODUCT(--ISNUMBER(SEARCH($B$1:$B$10,A1)))>0
Personally I prefer to do a COUNTIF against the range + a cell concatenated with wildcards:
=COUNTIF(A1:A6,CONCATENATE("*"&B1&"*"))
If you need it to return a boolean then you can use:
=IF(COUNTIF(A1:A6,CONCATENATE("*"&B1&"*")) > 0, TRUE, FALSE)

Excel search for a string and how many times a charactor is in the cell

I have a list in excel that contain location but some cell have multiple locations separated by " _ " character for Example "_ Location1 _ Location 2" When there are only 1 location I can use Sumif to search for string and add the numbers next to the cell as shown here
My problem is not searching for a string but searching for a character in a list and finding how many there are in the cell it find I was going to add the formula in a different cell then the ones shown above
example formula NOT REAL
=sum(Sumif($A$4:$A$250,"* ~ Location1*",$C$4:$C$250)/Search($A$4:$A$250," ~ "))
I know search does work like this but as an example code this is what I imagine
to find the sum of each location use this array formula:
=SUMPRODUCT((ISNUMBER(SEARCH(D4,$A$4:$A$9)))*($C$4:$C$9/(IF(ISNUMBER(FIND("_",$A$4:$A$9)),LEN($A$4:$A$9)-LEN(SUBSTITUTE($A$4:$A$9,"_","")),1))))
Being an array formula it needs to be confirmed with Ctrl-Shift-Enter. If done correctly then Excel will put {} around the formula.
Enter the formula in E4, Hit Ctrl-Shift-Enter, then copy/fill down.
Then to get the total for all simply sum the rows above.
To do it with regular formulas:
You will need a helper column with the following formula:
=C4/(IF(ISNUMBER(FIND("_",A4)),LEN(A4)-LEN(SUBSTITUTE(A4,"_","")),1))
I put mine in Column G.
Then we can use a simple SUMIF():
=SUMIF(A:A,"*" & D4 & "*",G:G)

Resources