IF Formula to calculate time based on status in another column

floggingmolly

Board Regular
Joined
Sep 14, 2019
Messages
167
Office Version
  1. 365
Platform
  1. Windows
I have a spreadsheet with a Status Column which is either N for new or O for opened. Then a column for the Transaction Time. And a column for Reference ID. I have a formula to calculate the time difference if for example Row 1 is N, and Row 2 is O and the reference ID matches. The problem is when there are say 2 rows consecutively with the status O and the same reference ID. In that case I just want to get the value from the row above it for the open time. Example:

Column J Column K Column L Column M
Msg Status Transaction Time Time Taken Reference #
N 12/4/2020 13:06 00001
O 12/4/2020 13:13 0.005115741 00001
N 12/16/2020 11:21 00002
O 12/16/2020 11:26 0.046342593 00002
O 12/17/2020 11:15 00002

So in the example above, everything works in my formula, except I would like for the second status of O I would like to have the value for time taken since it has the same Reference #. So the second message status of O can be either the value from the row above 0.046342593 since this is actually the first time they viewed the message, or it can the difference between the N status date 12/16/2020 and the O status of 12/17/2020, either one will suffice for what I am doing. The formula I have so far is =IF(AND(J2="N",M2=[@[ZG_REFERENCE_ID]]),[@[TRANSACTION_TIME]]-K2,"").

Any help would be appreciated. I can't seem to get it right.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
here my results of the time differences do not match yours, but hopefully you can use this to get yours to work how you want.
---------------
Book1
JKLMNO
1Msg Status Transaction Time Time TakenReference ID
2N12/4/20 13:061 
3O12/4/20 13:130.00511574110.004861111
4N12/16/20 11:212 
5O12/16/20 11:260.04634259320.003472222
6O12/17/20 11:1520.003472222
Sheet1
Cell Formulas
RangeFormula
O2:O6O2=IF(J2="N","",INDEX(Table1[[ Transaction Time ]],MATCH(1,(M2=Table1[Reference ID])*("O"=Table1[Msg Status]),0))-INDEX(Table1[[ Transaction Time ]],MATCH(1,(M2=Table1[Reference ID])*("N"=Table1[Msg Status]),0)))
 
Upvote 0

Forum statistics

Threads
1,215,012
Messages
6,122,682
Members
449,091
Latest member
peppernaut

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