Lebene

New Member
Joined
Sep 20, 2019
Messages
40
Platform
  1. Windows
Hi all,

I am using a formula which uses LEN and SUBSTITUTE. The formula works (I didn't learn it by building up, I got it from a tutorial), and I understand what LEN and SUBSTITUTE do separately, however, I don't understand what they are doing in this formula.

I was hoping anyone would explain it in very basic terms? As much as I like that the formula works, I want to also start to understand why the formulas do what they do so that I can begin to become more self-productive in building up formulas as I understand the logic.

Without further ado:
=SUMPRODUCT((LEN($J$2:$J$549)-LEN(SUBSTITUTE($J$2:$J$549, $A2, "")))/LEN($A2))

I use this formula for my lottery syndicate. It counts all the winning numbers from that game (J2:J549) for example, finding the number "01" (A2) in 01-16-23-28-29-(14). I don't understand what LEN and SUBSTITUTE are doing here to accurately sum up and display the frequency that these numbers show up. Especially the minus (-) and divide (/) segments.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
If you have
Book1
ABCDEFGHIJ
2231
316
4123
528
629
710
Sheet2
Cell Formulas
RangeFormula
F4F4=SUMPRODUCT((LEN($J$2:$J$7)-LEN(SUBSTITUTE($J$2:$J$7, $A2, "")))/LEN($A2))


since you are finding the length of a range you get multiple answers. the first LEN gives you
Rich (BB code):
=SUMPRODUCT(({1;2;2;2;2;2}-LEN(SUBSTITUTE($J$2:$J$7, $A2, "")))/LEN($A2))

the substitute gives you
Rich (BB code):
=SUMPRODUCT(({1;2;2;2;2;2}-LEN({"1";"16";"";"28";"29";"10"}))/LEN($A2))

since 28 was removed by substitute it now has a length of 0
Rich (BB code):
=SUMPRODUCT(({1;2;2;2;2;2}-{1;2;0;2;2;2})/LEN($A2))

when yo subtract them you get
Rich (BB code):
=SUMPRODUCT(({0;0;2;0;0;0})/LEN($A2))

the length of A2 is 2
Rich (BB code):
=SUMPRODUCT(({0;0;2;0;0;0})/2)

the division give you. by dividing the 2 is turned into a 1 so if there were multiple 23's then you would get multiple 1's in the array
Rich (BB code):
=SUMPRODUCT({0;0;1;0;0;0})

when there is only one array in sumpoduct as is the case here it is added to give you
1

If you had more then once instance of 23 (say 2)you would get something like this that would sum to 2
Code:
=SUMPRODUCT({0;0;1;1;0;0})
 
Upvote 0
If you have
Book1
ABCDEFGHIJ
2231
316
4123
528
629
710
Sheet2
Cell Formulas
RangeFormula
F4F4=SUMPRODUCT((LEN($J$2:$J$7)-LEN(SUBSTITUTE($J$2:$J$7, $A2, "")))/LEN($A2))


since you are finding the length of a range you get multiple answers. the first LEN gives you
Rich (BB code):
=SUMPRODUCT(({1;2;2;2;2;2}-LEN(SUBSTITUTE($J$2:$J$7, $A2, "")))/LEN($A2))

the substitute gives you
Rich (BB code):
=SUMPRODUCT(({1;2;2;2;2;2}-LEN({"1";"16";"";"28";"29";"10"}))/LEN($A2))

since 23 was removed by substitute it now has a length of 0
Rich (BB code):
=SUMPRODUCT(({1;2;2;2;2;2}-{1;2;0;2;2;2})/LEN($A2))

when yo subtract them you get
Rich (BB code):
=SUMPRODUCT(({0;0;2;0;0;0})/LEN($A2))

the length of A2 is 2
Rich (BB code):
=SUMPRODUCT(({0;0;2;0;0;0})/2)

the division give you. by dividing the 2 is turned into a 1 so if there were multiple 23's then you would get multiple 1's in the array
Rich (BB code):
=SUMPRODUCT({0;0;1;0;0;0})

when there is only one array in sumpoduct as is the case here it is added to give you
1

If you had more then once instance of 23 (say 2)you would get something like this that would sum to 2
Code:
=SUMPRODUCT({0;0;1;1;0;0})
You are a maverick! Thank you so much, this makes a lot of sense. In my cells I have all the numbers in one cell with dashes, but this still completely 100%
 
Upvote 0

Forum statistics

Threads
1,215,686
Messages
6,126,202
Members
449,298
Latest member
Jest

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