Dragging down date formulas
I am trying to drag down dates to populate year days using formulas. It does not go to the next day using drag down. Is there any trick to it? Here is the example
Date1= 01/01/2020
First Cell =$Date$1 - VALUE(YEARDAY($Date$1) - 1) = 01/01/2020
Second Cell =$Date$1 - VALUE(YEARDAY($Date$1) - 2) = 01/02/2020
Third Cell =$Date$1 - VALUE(YEARDAY($Date$1) - 3) = ......
thanks
Best Answer
-
It is because what determines the date is not changed by the dragfill.
The best way I can think of to enable to use of dragfill is to add in another column that has your variable in it.
Variable
-1
-2
-3
etc...
This can be dragfilled down the column to update the number. Then in your formula to input the date you would replace the number with a cell reference.
=$Date$1 - (YEARDAY($Date$1) - Variable@row)
Another option to remove the extra column would be to use a COUNT function to count how many rows are above it, then add that as your variable.
=$Date$1 - (YEARDAY($Date$1) - COUNT($Date$1:Date1))
If you put that in row 2, it will count 1 and add it to the date. Because we locked in the first row reference, and left the second row reference unlocked, the range will adjust to always count down to the row above the formula.
Answers
-
It is because what determines the date is not changed by the dragfill.
The best way I can think of to enable to use of dragfill is to add in another column that has your variable in it.
Variable
-1
-2
-3
etc...
This can be dragfilled down the column to update the number. Then in your formula to input the date you would replace the number with a cell reference.
=$Date$1 - (YEARDAY($Date$1) - Variable@row)
Another option to remove the extra column would be to use a COUNT function to count how many rows are above it, then add that as your variable.
=$Date$1 - (YEARDAY($Date$1) - COUNT($Date$1:Date1))
If you put that in row 2, it will count 1 and add it to the date. Because we locked in the first row reference, and left the second row reference unlocked, the range will adjust to always count down to the row above the formula.
-
thank you Paul, I used the 2nd solution and it worked.
-
Happy to help! 👍️
I actually thought of the second solution right before I submitted the first. Haha
Help Article Resources
Categories
- All Categories
- 14 Welcome to the Community
- Customer Resources
- 64.9K Get Help
- 441 Global Discussions
- 140 Industry Talk
- 472 Announcements
- 4.9K Ideas & Feature Requests
- 129 Brandfolder
- 148 Just for fun
- 68 Community Job Board
- 496 Show & Tell
- 33 Member Spotlight
- 2 SmartStories
- 300 Events
- 36 Webinars
- 7.3K Forum Archives
Check out the Formula Handbook template!