I have 2 columns Start Date
and End Date?
and I want to calculate a percentage from those dates based on associated years that they span across, in order to allocate the appropriate percentage to each year in their own separate columns.
My expected output is:
Start End Date? Year 1 - 2020 Year 2 - 2021 Year 3 - 2022
1/1/2020 12/30/2022 100% 100% 100%
1/1/2020 6/30/2021 100% 50% 0%
6/1/2021 0% 50% 100%
6/1/2021 6/30/2022 0% 50% 50%
1/1/2021 6/30/2021 0% 50% 0%
100% 100% 100%
This assumes that if there is a start date that is blank, the item is continuous and should be 100% for all years, and if there is an end date that is blank the item will be 100% each year after the year it starts. There will always be a blank end date when there is a blank start date.
Currently I am using an extremely long IFS formula, comparing the start Column A
and end dates Column B
to start and end dates for each year Column AP
& Column AQ
respectively
=IFS(OR(ISBLANK($B8),$B8=AP$1,AND($B8<AP$1,$C8>=AQ$1),AND($B8<AP$1,ISBLANK($C8))),100%,OR($C8<AP$1,$B8>AQ$1),0%,OR(AND($B8>AP$1,$C8>AQ$1),AND($B8>AP$1,$C8<AQ$1),AND($B8>AP$1,ISBLANK($C8)),AND($B8<AP$1,$C8<AQ$1)),(IF($B8<AP$1,DATEDIF(AP$1,$C8,"d")/DATEDIF(AP$1,AQ$1,"d"),DATEDIF($B8,$C8,"d")/DATEDIF(AP$1,AQ$1,"d"))))
The way I approached building this massive IFS formula, was by thinking there are three outcomes for each year: 100%, 0% or a percentage in between. The first two sub-if's seem to be working fine for capturing the 100%'s OR(ISBLANK($B18),$B18=AP$1,AND($B18<AP$1,$C18>=AQ$1),AND($B18<AP$1,ISBLANK($C18))),100%
or the 0%'s
OR($C18<AP$1,$B18>AQ$1),0%
but the section of the formula I've built to capture percentages in between doesn't seem to be capturing all situations, for example if there are blanks...
OR(AND($B23>AP$1,$C23>AQ$1),AND($B23>AP$1,$C23<AQ$1),AND($B23>AP$1,ISBLANK($C23)),AND($B23<AP$1,$C23<AQ$1)),(IF($B23<AP$1,DATEDIF(AP$1,$C23,"d")/DATEDIF(AP$1,AQ$1,"d"),DATEDIF($B23,$C23,"d")/DATEDIF(AP$1,AQ$1,"d"))))
I also feel as though there must be some way to do this without the nauseatingly long IFS formula...