SUMIF based on partial number match

charliefth

New Member
Joined
Jun 29, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I'm sure this is a relatively simple problem, but I am trying to SUMIF based on the first 4 digits of a number.
I have attached a picture of a simplified version of this problem.
The formula I have tried is shown in the formula bar and gives me an answer of 0.

This formula works fine when the "Lot Number" contains a letter, but doesn't work when they are just numerical.
So I'm assuming the concatenate &"*" function isn't meant to be used with numbers.

How do I change the formula to make it work with numerical values?
 

Attachments

  • SUMIF based on partial number match.png
    SUMIF based on partial number match.png
    28.3 KB · Views: 287

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
It would be easier with sumproduct than sumif
Excel Formula:
=SUMPRODUCT((--(LEFT($A$2:$A$8,4))=D3)*$B$2:$B$8)

edit:- here's a variation to the formula above that will work with text or numbers, any number of characters.
Excel Formula:
=SUMPRODUCT($B$2:$B$10*(LEFT($A$2:$A$10,LEN(D3))=D3&""))
 
Last edited:
Upvote 0
Are they always 6 digit?

=SUMIFS(B2:88,A2:A8,">="&D3*100,A2:A8,"<="&(D3*100)+100)
Thanks, this works!

I shortened the number for simplicity, they are actually always 8 digits.

For this would I use the following formula?

=SUMIFS(B2:B8,A2:A8,">="&D3*10000,A2:A8,"<="&(D3*10000)+10000)
 
Upvote 0
It would be easier with sumproduct than sumif
Excel Formula:
=SUMPRODUCT((--(LEFT($A$2:$A$8,4))=D3)*$B$2:$B$8)

edit:- here's a variation to the formula above that will work with text or numbers, any number of characters.
Excel Formula:
=SUMPRODUCT($B$2:$B$10*(LEFT($A$2:$A$10,LEN(D3))=D3&""))
Thanks, this works too!
However, I'm more au fait with SUMIFS so would rather use a complicated solution that I understand better
 
Upvote 0
Using that method, I would personally add 1 to D3 before multiplying.
Excel Formula:
=SUMIFS(B2:B8,A2:A8,">="&D3*10000,A2:A8,"<"&(D3+1)*10000)
Although I should point out that this method (done either way) will give you an error with a lot number that contains a letter. The second method that I suggested in my previous reply will work with any format and any number of characters.
 
Upvote 0

Forum statistics

Threads
1,215,473
Messages
6,125,018
Members
449,203
Latest member
tungnmqn90

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