using sumproduct to find shortest and longest occurrence

rhybeka

New Member
Joined
Mar 22, 2013
Messages
32
Hi all! I received help at another Excel forum for the first part of my problem ( finding the occurrences of temperatures reported from a probe : Count the number of occurences in a column thanks PCI!), and I happened to find more material over here that was helpful, so I thought I’d post the second half here. I'm a newb with a lot of these types of functions (SUMPRODUCT/MATCH/FREQUENCY, etc) I've been attempting for the past few days to cobble together a formula (or three) that would allow me to find:
• smallest occurrence for the probe(s) that were out of range or an alarm went off
• largest occurrence for that probe(s) that were out of range or an alarm went off
• average length of occurrence for the probe(s) that were out of range or an alarm went off

Something just isn’t clicking.

The original formula for the occurrences for the temp probe 1 in my sample data file is:
Rich (BB code):
=SUMPRODUCT((D1:D433<>1)*(D2:D434=1))

so for the first probe
• 12 occurrences where the temperature was out of the specified range
• 28 occurrences where the temperature set off an alarm.

So to count the shortest occurrence, I need to find a way to count the number of 1’s in the D column and have Excel just return to me the shortest one it found – most likely just a 1 but we have to check to make certain. There could be a few rarities that are longer though. Same basic theory for the longest occurrence, just reversing and having it return the largest occurrence of 1’s in column D. Since I can't seem to wrap my brain enough around the first two I haven't even tried an average :)


Would someone mind pointing me in the right direction??
Rich (BB code):
Excel 2010
ABCDEFGH
1DateTimeTemprature Probe 1out of rangealarmsTempurature Probe 2out of rangealarms
210/12/127:3068106710
310/12/128:0068106710
410/12/128:3068106710
510/12/129:0068106710
610/12/129:3068106710
710/12/1210:0068106710
810/12/1210:3068106810
910/12/1211:0069016810
1010/12/1211:3069016810
1110/12/1212:0069016810
1210/16/125:3069016901
1310/16/126:0069016901
1410/16/126:3069016901
1510/16/127:0068106901
1610/16/127:3069016901
1710/16/128:0069016901
1810/16/128:3069016901
1910/16/129:0069016901
2010/16/129:3069016901
2110/16/1215:0076017300
2210/16/1215:3076017400
2310/16/1216:0076017400
2410/16/1216:3076017400
2510/16/1217:0076017400
2610/16/1223:0069016901
2710/16/1223:3069016901
2810/17/120:0069016901
2910/17/120:3069016901
3010/17/121:0069016901
3110/17/121:3069016810
3210/17/122:0068106810
3310/17/122:3068106810
3410/17/123:0068106810
3510/17/123:3068106810
3610/17/124:0068106810
3710/17/124:3068106810
3810/17/125:0068106810
3910/17/125:3068106710
4010/17/126:0067106710
4110/17/126:3067106710
4210/17/127:0068106710
4310/17/127:3068106710
4410/17/128:0068106810
4510/17/128:3068106810
4610/17/129:0068106810
4710/17/129:3069016810
4810/17/1214:3075007300
4910/17/1215:0076017300
5010/17/1215:3077107400
5110/17/1216:0076017400
5210/17/1216:3077107400
5310/17/1217:0076017400
5410/17/1217:3076017400
5510/18/123:0069016901
5610/18/123:3069016901
5710/18/124:0069016901
5810/18/124:3069016901
5910/18/125:0069016901
6010/18/125:3069016901
6110/18/126:0069016810
6210/18/126:3069016810
6310/18/127:0069016810
6410/18/127:3068106810
6510/18/128:0068106810
6610/18/128:3069016901
6710/18/129:0069016901
6810/18/129:3069016901
6910/18/1223:3069017000
7010/19/120:0069016901
7110/19/120:3069016901
7210/19/121:0070006901
7310/19/121:3069016901
7410/19/125:3069016901
7510/19/126:0069016901
7610/19/126:3069016901
7710/19/127:0069016901
7810/19/127:3069016901
7910/19/128:0069016901
8010/19/128:3069016901
8110/19/129:0069016901
8210/19/129:3069016901
8310/20/125:0069016901
8410/20/125:3069016901
8510/20/126:0069016901
8610/20/126:3069016901
8710/20/127:0069016901
8810/20/127:3069016901
8910/20/128:0069016901
9010/20/128:3069016901
9110/20/129:0069016901
9210/20/129:3069016901
93Total27623246
94Overall Time (in hrs)13.531.016.023.0
95Occurences6835
96Shortest Occurrence
97Longest Occurrence
98Avg Length of Occurrence
<COLGROUP><COL><COL><COL><COL><COL><COL><COL><COL><COL></COLGROUP><THEAD> </THEAD><TBODY> </TBODY>
Sheet1
Worksheet Formulas
CellFormula
G1=D1
H1=E1
D2=IF(C2<=68,1,IF(C2>=77,1,0))
E2=IF(C2=69,1,IF(C2=76,1,0))
D94=IF(D93/2=0,"",D93/2)
E94=IF(E93/2=0,"",E93/2)
F94=IF(F93/2=0,"",F93/2)
D95=SUMPRODUCT((D1:D92<>1)*(D2:D93=1))
E95=SUMPRODUCT((E1:E92<>1)*(E2:E93=1))
<THEAD> </THEAD><TBODY> </TBODY>
<TBODY> </TBODY>
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
well, hopefully the title isn't scaring anyone off - I don't need to use sumproduct to find my shortest/longest occurrence if there is a better / easier way :) I've been trying to adapt a few formulas with no good results - think I'm doing something wrong.
 
Upvote 0
Looks like you want...

1. Control+shift+enter, not just enter
Rich (BB code):
=MIN(IF(FREQUENCY(IF($D$2:$D$92=1,ROW($D$2:$D$92)),
  IF($D$2:$D$92<>1,ROW($D$2:$D$92)))>0,FREQUENCY(IF($D$2:$D$92=1,ROW($D$2:$D$92)),
  IF($D$2:$D$92<>1,ROW($D$2:$D$92)))))

2. Control+shift+enter, not just enter
Rich (BB code):
=MAX(FREQUENCY(IF($D$2:$D$92=1,ROW($D$2:$D$92)),IF($D$2:$D$92<>1,ROW($D$2:$D$92))))
 
Upvote 0
Hi Aladin,

I think this also works to find the shortest occurence and it's shorter

=SMALL(FREQUENCY(IF($D$2:$D$433=1,ROW($D$2:$D$433)),IF($D$2:$D$433=1,IF($D$3:$D$434<>1,ROW($D$2:$D$433)))),2)

confirmed with Ctrl+Shift+Enter

M.
 
Upvote 0
Hi

Same idea but with another option for the Min:

=1/MAX(IFERROR(1/FREQUENCY(IF(D2:D92=1,ROW(D2:D92)),IF(D2:D92<>1,ROW(D2:D92))),0))

... confirmed with CSE


Remark: The "using sumproduct" in the title makes no sense to me.
Your objective is to "find shortest and longest occurrence", IMO that should be the title.
 
Upvote 0
Hi Aladin,

I think this also works to find the shortest occurence and it's shorter

=SMALL(FREQUENCY(IF($D$2:$D$433=1,ROW($D$2:$D$433)),IF($D$2:$D$433=1,IF($D$3:$D$434<>1,ROW($D$2:$D$433)))),2)

confirmed with Ctrl+Shift+Enter

M.

Hi

Same idea but with another option for the Min:

=1/MAX(IFERROR(1/FREQUENCY(IF(D2:D92=1,ROW(D2:D92)),IF(D2:D92<>1,ROW(D2:D92))),0))

... confirmed with CSE


Remark: The "using sumproduct" in the title makes no sense to me.
Your objective is to "find shortest and longest occurrence", IMO that should be the title.

The idea is to avoid an unjustified 0 in min case. The efficient alternative suggestions which effect that are of course ok.
 
Upvote 0
Thanks everybody! You are all rock stars :) I hadn't even realized I could use small/large - I have so much to learn! Trying to find the average length of an occurrence is most likely out of my league for the time being! I think I slightly understand the logic behind Aladin's formulas - PGC and Marcelo I'll have to noodle on yours a bit longer. :) And PGC you're right about my title - unfortunately I can't go back to change it that I know of.
 
Upvote 0
Thanks everybody! You are all rock stars :) I hadn't even realized I could use small/large - I have so much to learn! Trying to find the average length of an occurrence is most likely out of my league for the time being! I think I slightly understand the logic behind Aladin's formulas - PGC and Marcelo I'll have to noodle on yours a bit longer. :) And PGC you're right about my title - unfortunately I can't go back to change it that I know of.

You are welcome. The kernel idea is the conditional FREQUENCY expression.
 
Upvote 0
Thanks everybody! You are all rock stars :) I hadn't even realized I could use small/large - I have so much to learn! Trying to find the average length of an occurrence is most likely out of my league for the time being! I think I slightly understand the logic behind Aladin's formulas - PGC and Marcelo I'll have to noodle on yours a bit longer. :) And PGC you're right about my title - unfortunately I can't go back to change it that I know of.

You are welcome.

By the way:
To calculate the Average all you have to do is take the first formula provided by Aladin and change Min to AVERAGE.
Of course, confirming with Ctrl+Shift+Enter

Is also possible to adapt my formula to calculate the AVG - but for the moment let's stick with Aladin's formula.

M.
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,725
Members
448,987
Latest member
marion_davis

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