0

I have an excel file with two columns time and output. output column consist of two values 1 and 2. I want to make a calculate total time output 2 last in continuity i.e end time -start time. for example

    time          output       total
      2                2           4-2=2
      4                2
      6                1
      8                2           10-8=2
      10               2
      12               1
      14               1
      16               1
      18               2           22-18=4
      20               2
      22               2

Is there some easy way to so this as my data file is very large

2
  • Hi and welcome to the forum. Several issues with your post. 1) The headline doesn't correspond very well with your question, 2) Third example in total column seems to be incorrect, it should be 20-18=2, shouldn't it? 3) If I understand you correctly, you could achieve this by adding "=A3-A2" in [C2] and copy-pasting the formula to the bottom row. Completely standard...
    – Miqi180
    Feb 13, 2016 at 20:35
  • ya its suppose to be 20-18=2
    – amy
    Feb 13, 2016 at 22:47

1 Answer 1

0

Try this in C2 and copy down:

=IF(AND(B2=2,B1<>2),INDEX($A2:$A$30000,MATCH(1,$B2:$B$30000,0)-1)-A2,"")

The only caveat is that the last value in column B needs to be a 1. Or it will not do the last calculation correctly.

enter image description here


If you have Excel 2010 or later this formula does not care about the last values in column B. But depending the number of rows it will be slower in the calculations.

=IF(AND(B2=2,B1<>2),INDEX(A:A,AGGREGATE(15,6,ROW(2:$13)/($B2:$B$13 <>2),1)-1)-A2,"")

enter image description here

But it does require that the last row in the specified ranges be at least one larger than the last data row. It can be thousands larger, but that adds calculation times.

1
  • @amy Please mark answer as correct. It is something only you can do. Click on the green check mark by the answer. It will close the question as answered and reward me with points. Feb 13, 2016 at 23:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.