Forum Discussion
jfig9
Apr 16, 2024Copper Contributor
Help with formula for data analysis
Hi everyone,
Been trying to work on this formula for a while and cant quite get it, probably as I dont use excel often.
Column A is current age. Column B is the date of an event. Column C is where I would like the output of how old they were when the event occurred.
For example:
A B C
18 //age this year 23/11/2018 12 //years old in 2018
17 17/02/2020 13
02/04/2020 13
//preferably this line is all blank
16 09/11/2019 11
I am trying to ignore the blank spaces like in B4 while using A2 as the placeholder for the calculations that would require a number in A3. This is small example of a larger cohort, so take that into consideration please.
=IFERROR(-DATEDIF(B1,TODAY(),"Y"))+A1),"" <- this formula does not take into account the blank spaces but seems to work otherwise.
I have also messed around with IF(OR) and xlookup, but I am a bit short on time to learn it all at once.
Any help is appreciated,
Thanks
- Rodrigo_Steel Contributor
jfig9
Use this array formula on C1=IF(B1<>"", IF(A1<>"", A1, LOOKUP(2,1/(A$1:A1<>""),A$1:A1)) - (YEAR(TODAY()) - YEAR(B1)), "")
(use ctrl+shift+enter instead of enter key only after typing/pasting the formula)
It will check first if the corresponding row has a value on column B, if so, it uses the age on column A, if not, it uses the lookup function to fine the last non-empty cell in the array (A$1:A1)
then YEAR(TODAY()) - YEAR(B) calculates the number of years between the current year and the event year(B), then the formula subtracts that number from the age(A) determined in the previous step.