Sum duration values only if -3

BradleyS

Active Member
Joined
Oct 28, 2006
Messages
301
The table below shows an ID reference and each -3 (shown in red in my example only) is an accumulative count of the duration and needs to be added to the value above it.

So if the ID is NOT - 3 it will be just be the adjacent duration value. However, if the ID is -3 it now has to be added to the duration above it.

<b>Excel 2010</b><table cellpadding="2.5px" rules="all" style=";background-color: #FFFFFF ;border: 1px solid;border-collapse: collapse; border-color: #BBB"><colgroup><col width="25px" style="background-color: #DAE7F5 " /><col /><col /><col /><col /></colgroup><thead><tr style=" background-color: #DAE7F5 ;text-align: center;color: #161120"><th></th><th>N</th><th>O</th><th>P</th><th>Q</th></tr></thead><tbody><tr ><td style="color: #161120;text-align: center;">1</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">No.</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">ID</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">duration</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">SUM</td></tr><tr ><td style="color: #161120;text-align: center;">2</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">1</td><td style="text-align: center;;">0</td><td style="text-align: center;;">5</td><td style=";"></td></tr><tr ><td style="color: #161120;text-align: center;">3</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">2</td><td style="text-align: center;;">2</td><td style="text-align: center;;">5</td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">4</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">3</td><td style="font-weight: bold;text-align: center;color: #FF0000;;">-3</td><td style="text-align: center;;">5</td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">5</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">4</td><td style="font-weight: bold;text-align: center;color: #FF0000;;">-3</td><td style="text-align: center;;">5</td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">6</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">5</td><td style="text-align: center;;">0</td><td style="text-align: center;;">5</td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">7</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">6</td><td style="text-align: center;;">1</td><td style="text-align: center;;">5</td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">8</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">7</td><td style="text-align: center;;">0</td><td style="text-align: center;;">5</td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">9</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">8</td><td style="text-align: center;;">0</td><td style="text-align: center;;">5</td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">10</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">9</td><td style="text-align: center;;">2</td><td style="text-align: center;;">5</td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">11</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">10</td><td style="font-weight: bold;text-align: center;color: #FF0000;;">-3</td><td style="text-align: center;;">5</td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">12</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">11</td><td style="text-align: center;;">0</td><td style="text-align: center;;">5</td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">13</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">12</td><td style="text-align: center;;">0</td><td style="text-align: center;;">5</td><td style="text-align: right;;"></td></tr></tbody></table><p style="width:7.8em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid #BBB;border-top:none;text-align: center;background-color: #DAE7F5 ;color: #161120">Session_Slots</p><br /><br /><table width="85%" cellpadding="2.5px" rules="all" style=";border: 2px solid black;border-collapse:collapse;padding: 0.4em;background-color: #FFFFFF " ><tr><td style="padding:6px" ><b>Array Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: #FFFFFF ;border-collapse: collapse; border-color: #BBB"><thead><tr style=" background-color: #DAE7F5 ;color: #161120"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: #DAE7F5 ;color: #161120">Q2</th><td style="text-align:left">{=IF(<font color="Blue">O2=-3,SUM(<font color="Red">P2:INDEX(<font color="Green">P2:$P$12,MATCH(<font color="Purple">TRUE,(<font color="Teal">P3:$P$12=""</font>),0</font>)</font>)</font>),""</font>)}</td></tr></tbody></table><b>Entered with Ctrl+Shift+Enter.</b> If entered correctly, Excel will surround with curly braces {}.
<b>Note: Do not try and enter the {} manually yourself</b></td></tr></table><br />

You can see my attempt at trying to make this work, but I'm having no luck

What I need is for the final output to look like this:
<b>Excel 2010</b><table cellpadding="2.5px" rules="all" style=";background-color: #FFFFFF ;border: 1px solid;border-collapse: collapse; border-color: #BBB"><colgroup><col width="25px" style="background-color: #DAE7F5 " /><col /><col /><col /><col /></colgroup><thead><tr style=" background-color: #DAE7F5 ;text-align: center;color: #161120"><th></th><th>N</th><th>O</th><th>P</th><th>Q</th></tr></thead><tbody><tr ><td style="color: #161120;text-align: center;">17</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">No.</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">ID</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">duration</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">SUM</td></tr><tr ><td style="color: #161120;text-align: center;">18</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">1</td><td style="text-align: center;;">0</td><td style="text-align: center;;">5</td><td style="text-align: right;;">5</td></tr><tr ><td style="color: #161120;text-align: center;">19</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">2</td><td style="text-align: center;;">2</td><td style="text-align: center;;">5</td><td style="text-align: right;;">15</td></tr><tr ><td style="color: #161120;text-align: center;">20</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">3</td><td style="font-weight: bold;text-align: center;color: #FF0000;;">-3</td><td style="text-align: center;;">5</td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">21</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">4</td><td style="font-weight: bold;text-align: center;color: #FF0000;;">-3</td><td style="text-align: center;;">5</td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">22</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">5</td><td style="text-align: center;;">0</td><td style="text-align: center;;">5</td><td style="text-align: right;;">5</td></tr><tr ><td style="color: #161120;text-align: center;">23</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">6</td><td style="text-align: center;;">1</td><td style="text-align: center;;">5</td><td style="text-align: right;;">5</td></tr><tr ><td style="color: #161120;text-align: center;">24</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">7</td><td style="text-align: center;;">0</td><td style="text-align: center;;">5</td><td style="text-align: right;;">5</td></tr><tr ><td style="color: #161120;text-align: center;">25</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">8</td><td style="text-align: center;;">0</td><td style="text-align: center;;">5</td><td style="text-align: right;;">5</td></tr><tr ><td style="color: #161120;text-align: center;">26</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">9</td><td style="text-align: center;;">2</td><td style="text-align: center;;">5</td><td style="text-align: right;;">10</td></tr><tr ><td style="color: #161120;text-align: center;">27</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">10</td><td style="font-weight: bold;text-align: center;color: #FF0000;;">-3</td><td style="text-align: center;;">5</td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">28</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">11</td><td style="text-align: center;;">0</td><td style="text-align: center;;">5</td><td style="text-align: right;;">5</td></tr><tr ><td style="color: #161120;text-align: center;">29</td><td style="text-align: center;color: #9C6500;background-color: #FFEB9C;;">12</td><td style="text-align: center;;">0</td><td style="text-align: center;;">5</td><td style="text-align: right;;">5</td></tr></tbody></table><p style="width:7.8em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid #BBB;border-top:none;text-align: center;background-color: #DAE7F5 ;color: #161120">Session_Slots</p><br /><br />

Any help will be most appreciated. Thank you in advance.
 

Some videos you may like

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Oaktree

MrExcel MVP
Joined
Jun 20, 2002
Messages
7,996
Try this in Q2:

Code:
{=IF(O2=-3,"",IFNA(SUM(OFFSET(P2,,,MATCH(FALSE,O3:$O$13=-3,0))),P2))}

copied down.
 
Last edited:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,670
Office Version
  1. 365
Platform
  1. Windows
Try replacing the IFNA with IFERROR
 

BradleyS

Active Member
Joined
Oct 28, 2006
Messages
301

ADVERTISEMENT

Perfect. Thank you both so much.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,670
Office Version
  1. 365
Platform
  1. Windows
Glad we could help & thanks for the feedback
 

Oaktree

MrExcel MVP
Joined
Jun 20, 2002
Messages
7,996
FWIW, IFNA is a real function, but it was introduced in Excel 2013.

Sounds like you're using a version that's a little older, but not older than v2007 (when IFERROR was introduced) ... if some future reader is using an older version than 2007, we'd have to use the older IF(ISNA(value),P2,value) structure as opposed to the newer IFERROR or IFNA functions.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,832
Messages
5,627,152
Members
416,224
Latest member
RichardHell

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
Top