Calculating Number of Days (Date Calculation)

Pesopakis

New Member
Joined
Feb 21, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I am trying to calculate number of days record is "open". If no end date is available I am using Today's Date for the calculation.

3 columns in my example

[P] = Start Date
[Q] = End Date
[R] = Days Record Open Formula:
=IF(AND(P2<>"", Q2<>""), (Q2-P2), IF(AND(P2<>"", Q2=""), (TODAY()-P2), 0))

Everything calculates correct. But... when a new row is added to the table, column [R] shows "44248". I would like it to show "0".
However, If I enter a value in column [P], then immediately delete it... column [R] then shows "0" as I want it. Why do I have to trigger it? Can I make this default to zero when a new row is added to the table before any data is initially inputted for [P] and [Q] ?

Thanks,
 

Attachments

  • ExcelQuestion.jpg
    ExcelQuestion.jpg
    178.6 KB · Views: 9

Some videos you may like

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Zot

Well-known Member
Joined
Nov 26, 2020
Messages
1,051
Office Version
  1. 2016
Platform
  1. Windows
Maybe something is wrong in you sheet. Do you have on status bar stating there is circular reference?
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
48,400
Office Version
  1. 365
Platform
  1. Windows
Welcome to the MrExcel board!

If you have a situation as shown in your image where P2 appears to be blank, if you go to a blank cell elsewhere in the worksheet and enter this formula, what does it return?
=LEN(P2)

I'm wondering if column P contains zeros that are hidden by conditional formatting or by a custom cell format?

Alternatively you could try this formula
Excel Formula:
=IF(AND(P2>0,Q2>0),Q2-P2,IF(AND(P2>0,Q2=0),TODAY()-P2,0))
 
Solution

Saba Sabaratnam

Board Regular
Joined
May 26, 2018
Messages
196
or there are some zeros in P column. if so, you may want to try this formula.

=IF(AND(COUNTIFS(P2,">="&DATE(1900,1,1),P2,"<"&TODAY())>0,COUNTIFS(Q2,">="&DATE(1900,1,1),Q2,"<"&TODAY())>0), (Q2-P2), IF(AND(COUNTIFS(P2,">="&DATE(1900,1,1),P2,"<"&TODAY())>0, Q2=""), (TODAY()-P2), 0))'


it will ignore or text values in Column P as shown below.

1613968463046.png

Kind regards

Saba
 

Pesopakis

New Member
Joined
Feb 21, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Thank you both. A combination of the two i think will get me where I want to be. I appreciate the help.
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
48,400
Office Version
  1. 365
Platform
  1. Windows
Cheers. Hope it works out for you. :)

Did you determine whether zeros in column P (hidden or otherwise) were the problem?
 

Watch MrExcel Video

Forum statistics

Threads
1,128,088
Messages
5,628,600
Members
416,327
Latest member
Chimay

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