Finding a rolling pair of values in a long list

Roghaltz

New Member
Joined
Nov 26, 2015
Messages
26
Hello all,
I wasn't sure exactly how to describe this problem and I suspect the solution is simple (however, I have been pulling my hair out trying to find it). We have a bunch of salesmen participating in a variety of sales events. We are trying to find the sum of the outputs by pairs of event types on a rolling basis.

There are three main event types (a,b,c in Column B). The first two events in the example below are an "a" and a "b", thus the first pair (and desired output) is "ab" (in column C). Ultimately I would like to sum the output based on the Last 2 Event Types (i.e. ab= ..., ac=..., ba=..., etc). This is easy using sumif once I have the "Last 2 Event Types" in column C.

There can be a different number of salesmen in each event (usually 6-10). The event types occur in pretty much random order.

There many events in column B so I don't want do Last 2 Event Types (Column C) by hand (if possible).

Excel 2010
ABCD
1SalesmanEventTypeLast 2 Event TypesOutput
2a1a
3a2a
4a3a
5a4a
6a5a
7a6a
8b1b
9b2b
10b3b
11b4b
12b5b
13b6b
14b7bab50
15c1c
16c2c
17c3c
18c4c
19c5c
20c6c
21c7c
22c8c
23c9cbc62
24b1b
25b2b
26b3b
27b4b
28b5b
29b6b
30b8bcb47
31c1c
32c2c
33c3c
34c4c
35c5c
36c6c
37c7cbc39

<tbody>
</tbody>
Sheet1
Any help would be appreciated.

Thank you.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi,

Actually, I don't think the solution is as easy as you might think, at least not for me.

My solution requires you to add a helper column, Column D in my sample below.
Copy formula in D2 down, and formula in C2 down, then hide Column D.


Excel 2010
ABCDE
1SalesmanEventTypeLast 2 Event TypesOutput
2a1a a
3a2aa
4a3aa
5a4aa
6a5aa
7a6aa
8b1bab
9b2bab
10b3bab
11b4bab
12b5bab
13b6bab
14b7babab50
15c1cbc
16c2cbc
17c3cbc
18c4cbc
19c5cbc
20c6cbc
21c7cbc
22c8cbc
23c9cbcbc62
24b1bcb
25b2bcb
26b3bcb
27b4bcb
28b5bcb
29b6bcb
30b8bcbcb47
31c1cbc
32c2cbc
33c3cbc
34c4cbc
35c5cbc
36c6cbc
37c7cbcbc39
Sheet1
Cell Formulas
RangeFormula
C2=IF(AND(LEN(D2)>1,D2<>D3),D2,"")
D2=IF(D1="",B2,IF(B2<>B1,B1&B2,D1))


PS. No idea how your Column E Output numbers work, they don't seem to add up.
 
Upvote 0
Thank you. That worked great.

The output column comes from somewhere else in the model, forgot to mention that part.You answered my question completely.

Thanks again.
 
Upvote 0
Actually, was just looking it over more carefully and it works well as long the same event type doesn't occur twice in a row. Unfortunately, In my model it often does (i.e. aa, bb, cc). In these cases Column C is blank. Should have mentioned that.

Any thoughts?

Thanks.
 
Upvote 0
Can you show a sample of these occurrences?
Does the Salesman column (A) change accordingly?
 
Upvote 0
Here is an example. I also have a DateID column (added below) to show that every event is unique (i.e. there were back to back "a" events below, but one was in October and then one in November). Thus, the first pairing is "aa".

Excel 2010
ABCDE
1DateSalesmanEventTypeDateEventIDLast 2 Event Types
2Oct-15a1aOct-15-a
3Oct-15a2aOct-15-a
4Oct-15a3aOct-15-a
5Oct-15a4aOct-15-a
6Oct-15a5aOct-15-a
7Oct-15a6aOct-15-a
8Nov-15a1aNov-15-a
9Nov-15a2aNov-15-a
10Nov-15a3aNov-15-a
11Nov-15a4aNov-15-a
12Nov-15a5aNov-15-a
13Nov-15a6aNov-15-a
14Nov-15a7aNov-15-aaa
15Nov-15b1bNov-15-b
16Nov-15b2bNov-15-b
17Nov-15b3bNov-15-b
18Nov-15b4bNov-15-b
19Nov-15b5bNov-15-b
20Nov-15b6bNov-15-b
21Nov-15b7bNov-15-bab
22Nov-15c1cNov-15-c
23Nov-15c2cNov-15-c
24Nov-15c3cNov-15-c
25Nov-15c4cNov-15-c
26Nov-15c5cNov-15-c
27Nov-15c6cNov-15-c
28Nov-15c7cNov-15-c
29Nov-15c8cNov-15-c
30Nov-15c9cNov-15-cbc
31Nov-15b1bNov-15-b
32Nov-15b2bNov-15-b
33Nov-15b3bNov-15-b
34Nov-15b4bNov-15-b
35Nov-15b5bNov-15-b
36Nov-15b6bNov-15-b
37Nov-15b8bNov-15-bcb

<colgroup><col style="width: 25pxpx"><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1
Hope this helps. Let me know if you need additional info.
 
Upvote 0
Hi Roghaltz,

Thanks for providing the additional info, that helps.

Use the following updated formulas, let me know if it works for your scenarios, and if you have further requirements.


Excel 2010
ABCDEF
1DateSalesmanEventTypeDateEventIDLast 2 Event Types
215-Octa1aOct-15-a a
315-Octa2aOct-15-aa
415-Octa3aOct-15-aa
515-Octa4aOct-15-aa
615-Octa5aOct-15-aa
715-Octa6aOct-15-aa
815-Nova1aNov-15-aaa
915-Nova2aNov-15-aaa
1015-Nova3aNov-15-aaa
1115-Nova4aNov-15-aaa
1215-Nova5aNov-15-aaa
1315-Nova6aNov-15-aaa
1415-Nova7aNov-15-aaaaa
1515-Novb1bNov-15-bab
1615-Novb2bNov-15-bab
1715-Novb3bNov-15-bab
1815-Novb4bNov-15-bab
1915-Novb5bNov-15-bab
2015-Novb6bNov-15-bab
2115-Novb7bNov-15-babab
2215-Novc1cNov-15-cbc
2315-Novc2cNov-15-cbc
2415-Novc3cNov-15-cbc
2515-Novc4cNov-15-cbc
2615-Novc5cNov-15-cbc
2715-Novc6cNov-15-cbc
2815-Novc7cNov-15-cbc
2915-Novc8cNov-15-cbc
3015-Novc9cNov-15-cbcbc
3115-Novb1bNov-15-bcb
3215-Novb2bNov-15-bcb
3315-Novb3bNov-15-bcb
3415-Novb4bNov-15-bcb
3515-Novb5bNov-15-bcb
3615-Novb6bNov-15-bcb
3715-Novb8bNov-15-bcbcb
Sheet2
Cell Formulas
RangeFormula
E2=IF(AND(LEN(F2)>1,F2<>F3),F2,"")
F2=IF(F1="",C2,IF(D2<>D1,C1&C2,F1))


Copy F2 formula down, E2 formula down, hide Column F.
 
Upvote 0
Hi again,

Ignore the above post, it won't work if you have the same event 3 times or more in a row, I've made changes to the formula, use these instead.
These should work even when you have the same event occurring more than twice in a row, as long as the dates are different, let me know if it works for your scenarios, and if you have further requirements.


Excel 2010
ABCDEF
1DateSalesmanEventTypeDateEventIDLast 2 Event Types
215-Octa1aOct-15-a a
315-Octa2aOct-15-aa
415-Octa3aOct-15-aa
515-Octa4aOct-15-aa
615-Octa5aOct-15-aa
715-Octa6aOct-15-aa
815-Nova1aNov-15-aaa
915-Nova2aNov-15-aaa
1015-Nova3aNov-15-aaa
1115-Nova4aNov-15-aaa
1215-Nova5aNov-15-aaa
1315-Nova6aNov-15-aaa
1415-Nova7aNov-15-aaaaa
1515-Novb1bNov-15-bab
1615-Novb2bNov-15-bab
1715-Novb3bNov-15-bab
1815-Novb4bNov-15-bab
1915-Novb5bNov-15-bab
2015-Novb6bNov-15-bab
2115-Novb7bNov-15-babab
2215-Novc1cNov-15-cbc
2315-Novc2cNov-15-cbc
2415-Novc3cNov-15-cbc
2515-Novc4cNov-15-cbc
2615-Novc5cNov-15-cbc
2715-Novc6cNov-15-cbc
2815-Novc7cNov-15-cbc
2915-Novc8cNov-15-cbc
3015-Novc9cNov-15-cbcbc
3115-Novb1bNov-15-bcb
3215-Novb2bNov-15-bcb
3315-Novb3bNov-15-bcb
3415-Novb4bNov-15-bcb
3515-Novb5bNov-15-bcb
3615-Novb6bNov-15-bcb
3715-Novb8bNov-15-bcbcb
Sheet2
Cell Formulas
RangeFormula
E2=IF(AND(LEN(F2)>1,D2<>D3),F2,"")
F2=IF(F1="",C2,IF(D2<>D1,C1&C2,F1))


Copy F2 formula down, E2 formula down, hide Column F.
 
Upvote 0

Forum statistics

Threads
1,216,117
Messages
6,128,937
Members
449,480
Latest member
yesitisasport

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