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: 11

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Maybe something is wrong in you sheet. Do you have on status bar stating there is circular reference?
 
Upvote 0
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))
 
Upvote 0
Solution
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
 
Upvote 0
Thank you both. A combination of the two i think will get me where I want to be. I appreciate the help.
 
Upvote 0
Cheers. Hope it works out for you. :)

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

Forum statistics

Threads
1,213,558
Messages
6,114,297
Members
448,564
Latest member
ED38

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