Formula to sum multiple sequences/ranges of values within an array?

tokendad

New Member
Joined
Jul 3, 2024
Messages
1
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
First, hello everyone I'm new here! :)

I have been following this forum for quite a while, and it has always been a valuable resource for finding solutions to my Excel queries. :) However, I now have a question that I haven't been able to find an answer to, and I'm hoping you can assist me with it. ;)

Example.xlsx
ABC
1LocationTimeValue
2LondonArrival5
3LondonDeparture0
4UnderwayNoon Report1
5LiverpoolArrival6
6LiverpoolDeparture7
7UnderwayEvening Report9
8BlackpoolArrival2
9BlackpoolNoon Report8
10BlackpoolDeparture4
11UnderwayEvening Report3
12LondonArrival1
13LondonDeparture2
14NottinghamArrival5
15NottinghamNoon Report9
16NottinghamDeparture3
17LiverpoolArrival6
18LiverpoolDeparture2
19UnderwayEvening Report3
20ShrewsburyArrival3
21ShrewsburyDeparture1
22UnderwayEvening Report7
23LondonArrival5
24LondonDeparture3
25LiverpoolArrival1
26LiverpoolDeparture9
27UnderwayNoon Report2
28BirminghamArrival8
Example


I have an Excel spreadsheet where I need to calculate the sum of values in column C whenever columns A and B show a sequence from "London Arrival" to "Liverpool Departure". This sequence must occur exactly in that order; any other sequence should not be considered. The intended result in the example provided would be the sum of C2:C6, C12:C18, and C23:C26, which equals 65.

I attempted to solve the problem using two helper columns. The first helper column uses the formula:
Excel Formula:
=IF(OR(AND(A2="London", B2="Arrival"), AND(A2="Liverpool", B2="Departure")), 1, 0)
The second helper column uses:
Excel Formula:
=IF(E2 + F1 = 1, 1, 0)
This setup allowed me to apply SUMIF to get the result:
Excel Formula:
=SUMIF(F:F, 1, C:C) + SUMIFS(C:C, A:A, "Liverpool", B:B, "Departure")

Example.xlsx
ABCDEFGHI
1LocationTimeValue
2LondonArrival511SUM65
3LondonDeparture001
4UnderwayNoon Report101
5LiverpoolArrival601
6LiverpoolDeparture710
7UnderwayEvening Report900
8BlackpoolArrival200
9BlackpoolNoon Report800
10BlackpoolDeparture400
11UnderwayEvening Report300
12LondonArrival111
13LondonDeparture201
14NottinghamArrival501
15NottinghamNoon Report901
16NottinghamDeparture301
17LiverpoolArrival601
18LiverpoolDeparture210
19UnderwayEvening Report300
20ShrewsburyArrival300
21ShrewsburyDeparture100
22UnderwayEvening Report700
23LondonArrival511
24LondonDeparture301
25LiverpoolArrival101
26LiverpoolDeparture910
27UnderwayNoon Report200
28BirminghamArrival800
Example
Cell Formulas
RangeFormula
E2:E28E2=IF(OR(AND(A2="London",B2="Arrival"),AND(A2="Liverpool",B2="Departure")),1,0)
F2:F28F2=IF(E2+F1=1,1,0)
I2I2=SUMIF(F:F,1,C:C)+SUMIFS(C:C,A:A,"Liverpool",B:B,"Departure")


However, this workaround has limitations. It only functions correctly when "London Arrival" appears first in column A. If "Liverpool Departure" is the initial entry, it disrupts the calculation. Additionally, I would prefer a single formula solution without needing helper columns.

I would greatly appreciate any assistance with this issue.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Are you open to using VBA to create a custom formula, or no?
 
Upvote 0
How about
Excel Formula:
=SUM(SIGN(SCAN(0,A2:A28&"|"&B2:B28,LAMBDA(a,b,IF(b="london|arrival",1,IF(AND(b="liverpool|departure",a=1),2,IF(a=1,1,0))))))*C2:C28)
 
Upvote 0

Forum statistics

Threads
1,223,887
Messages
6,175,199
Members
452,617
Latest member
Narendra Babu D

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