Sumif wildcard

Renevatia

New Member
Joined
May 26, 2018
Messages
12
Hi, new here. Been scratching my head around this for while.

I am currently using a =sum(sumif(A1:A10, {"*text1*","*text2*","*text3*"}, B1:B10)) formula to replace a really messy =sum(vlookup^n)
=sumif(A1:A10, C1, B1:B10) would work with a reference but I cannot throw in multiple references.
I am wondering if there is any way I can use cell reference for the criteria array for the sumif function. Everything I've tried so far seems to throw syntax error. Only thing that works is explicit text.
Since array is throwing wildcard kind of like a query is there a way for me to toss an OR statement in there to concatenate the entire criteria?

Are there any syntax that would support the following structures:

=sumif(A1:A10, C1, B1:B10)
where C1.text = *text1*|*text2*|*text3*

or

=sum(sumif(A1:A10, {C1, C2, C3}, B1:B10))
where C#.text = *text#*

I know I could simply hard code the criteria in or use multiple sumif or sumifs with cell reference, but that may still end up too messy and I would not be able to use dynamic range / range sizes for this method.
The only other solution I can think of is to bandage this with is a macro to populate the formulas.

plssendhelp
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Re: Sumif wildcard help

If each cell value includes the wildcard characters (ie. *text1*), try...

=SUMPRODUCT(SUMIF(A1:A10,C1:C3,B1:B10))

If each cell value doesn't include the wildcard characters (ie. text1), try...

=SUMPRODUCT(SUMIF(A1:A10,"*"&C1:C3&"*",B1:B10))

Hope this helps!
 
Upvote 0
Re: Sumif wildcard help

If each cell value includes the wildcard characters (ie. *text1*), try...

=SUMPRODUCT(SUMIF(A1:A10,C1:C3,B1:B10))

If each cell value doesn't include the wildcard characters (ie. text1), try...

=SUMPRODUCT(SUMIF(A1:A10,"*"&C1:C3&"*",B1:B10))

Hope this helps!
Thank you, I didn't realize sumproduct can be used like that.

However, I realized an inherent problem with the sum and sumif. Unions in those sets are counted twice so when I passed in "*" as one of the sumif it gave me a number greater than the sum of all return column.
This means even explicit declaration of the array like {"*text1*","*text2*","*text3*"} wouldn't work since it works like a loop of sumif instead of just a single query of multiple OR statements.
 
Upvote 0
Re: Sumif wildcard help

Can you post a small sample of the data, the criteria involved, and the expected result?
 
Last edited:
Upvote 0
Re: Sumif wildcard help

Sub-CategoryProduct NameSalesQuantityDiscountProfit
BookcasesBush Somerset Collection Bookcase261.962041.9136
ChairsHon Deluxe Fabric Upholstered Stacking Chairs, Rounded Back731.9430219.582
LabelsSelf-Adhesive Address Labels for Typewriters by Universal14.62206.8714
TablesBretford CR4500 Series Slim Rectangular Table957.577550.45-383.031
StorageEldon Fold 'N Roll Cart System22.36820.22.5164
FurnishingsEldon Expressions Wood and Plastic Desk Accessories, Cherry Wood48.867014.1694
ArtNewell 3227.28401.9656
PhonesMitel 5320 IP Phone VoIP phone907.15260.290.7152
BindersDXL Angle-View Binders with Locking Rings by Samsill18.50430.25.7825
AppliancesBelkin F5C206VTEL 6 Outlet Surge114.95034.47
TablesChromcraft Rectangular Conference Tables1706.18490.285.3092
PhonesKonftel 250 Conference phone - Charcoal black911.42440.268.3568
PaperXerox 196715.55230.25.4432

<colgroup><col><col><col><col><col><col></colgroup><tbody>
</tbody>


Sum of total Column("Quantity") = 55

___________________________________________________________________________________________________
Where H1:H4 = {*one*, *irs*, *, *}

Desired result:
1. MagicSumIf(A:A, "*one*|*irs*", D:D) = 13
2. MagicSumIf(A:A, "*one*|*irs*|*", D:D) = 55
or
3. MagicSumIf(A:A, H1:H3, D:D) = 55
4. MagicSumIf(A:A, H1:H4, D:D) = 55

Current result:
1. Sum(SumIf(A:A, H1:H2, D:D) = 13
2. Sum(SumIf(A:A, H1:H3, D:D) = 68
3. Sum(SumIf(A:A, H1:H4, D:D) = 123
 
Upvote 0
Re: Sumif wildcard help

In that case, try...

Code:
=IF(ISNUMBER(MATCH("~*",H1:H4,0)),SUM(D:D),SUMPRODUCT(SUMIF(A:A,H1:H4,D:D)))

 
Upvote 0
Re: Sumif wildcard help

In that case, try...

Code:
=IF(ISNUMBER(MATCH("~*",H1:H4,0)),SUM(D:D),SUMPRODUCT(SUMIF(A:A,H1:H4,D:D)))


This is returning double counted entries as long as the sum is not greater than the total sum of column
Lookup with "Art" and "*rt would return the "Art" Row return value of 4 twice when it should only picked up once if it was a query with "Art"|"*rt" equivalent syntax.
 
Upvote 0
Re: Sumif wildcard help

In that case, try...

=SUM(IF(MMULT(IF(ISNUMBER(SEARCH(TRANSPOSE(H1:H4),A2:A14)),1,0),ROW(H1:H4)^0)>0,D2:D14))

...confirmed with CONTROL+SHIFT+ENTER. Although, if the criteria range (ie. H1:H4) can contain empty cells, try the following instead...

=SUM(IF(MMULT(IF(LEN(TRANSPOSE(H1:H4))>0,IF(ISNUMBER(SEARCH(TRANSPOSE(H1:H4),A2:A14)),1,0),0),ROW(H1:H4)^0)>0,D2:D14))

...which also needs to be confirmed with CONTROL+SHIFT+ENTER.

Hope this helps!
 
Upvote 0
Re: Sumif wildcard help

In that case, try...

=SUM(IF(MMULT(IF(ISNUMBER(SEARCH(TRANSPOSE(H1:H4),A2:A14)),1,0),ROW(H1:H4)^0)>0,D2:D14))

...confirmed with CONTROL+SHIFT+ENTER. Although, if the criteria range (ie. H1:H4) can contain empty cells, try the following instead...

=SUM(IF(MMULT(IF(LEN(TRANSPOSE(H1:H4))>0,IF(ISNUMBER(SEARCH(TRANSPOSE(H1:H4),A2:A14)),1,0),0),ROW(H1:H4)^0)>0,D2:D14))

...which also needs to be confirmed with CONTROL+SHIFT+ENTER.

Hope this helps!

That is a really nice way of using arrays!
This works for my current application, but the formula is evaluating all lookup values as *text* since search function finds any match instead of exact match with wildcard.

Is there a way that I can use arrays as toggle but also take advange of wildcard lookup such as the ones in Sumif criteria. Match only throws back the first occurance of each lookup value unfortunately.
 
Upvote 0
Re: Sumif wildcard help

Can you please elaborate, and include some sample data along with the expected result?
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,488
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top