Filtering dates

tigerzen

Board Regular
Joined
Mar 8, 2023
Messages
165
Office Version
  1. 365
Platform
  1. Windows
I have stumbled across this formula which calculates YTD spanning multiple years. I don't really understand what the *($A$3:$A$26<=$A3) part does in the formula. Without it, the formula does not work. I'd like to understand it a little better and perhaps the formula I have is not the best or most efficient way of calculating YTD when you have multiple years so am open to suggestions on how one might calculate YTDs within their particular years if you have data spanning many years.

Book10
ABC
1
2MonthAmountYTD
31/01/20191,2561,256
428/02/20191,3692,625
531/03/20191,0183,643
630/04/20191,4065,049
731/05/20199926,041
830/06/20191,3647,405
931/07/20191,4978,902
1031/08/20191,32210,224
1130/09/20191,04211,266
1231/10/20191,21412,480
1330/11/201993913,419
1431/12/20191,28414,703
1531/01/20201,0731,073
1629/02/20201,4242,497
1731/03/20201,2833,780
1830/04/20209734,753
1931/05/20201,0635,816
2030/06/20209716,787
2131/07/20201,4408,227
2231/08/20201,1919,418
2330/09/20201,10310,521
2431/10/202088211,403
2530/11/20201,48012,883
2631/12/20201,38314,266
Sheet1
Cell Formulas
RangeFormula
C3:C26C3=SUM(FILTER($B$3:$B$26,(YEAR($A$3:$A$26)=YEAR($A3))*($A$3:$A$26<=$A3)))
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi, that part is specifically restricting the filtered rows to those that are less than or equal to the date in column A for the row the formula is on.

SUMIFS() might be a little more efficient, but I doubt there's much in it either way.

Book1
ABC
1
2MonthAmountYTD
301/01/201912561256
428/02/201913692625
531/03/201910183643
630/04/201914065049
731/05/20199926041
830/06/201913647405
931/07/201914978902
1031/08/2019132210224
1130/09/2019104211266
1231/10/2019121412480
1330/11/201993913419
1431/12/2019128414703
1531/01/202010731073
1629/02/202014242497
1731/03/202012833780
1830/04/20209734753
1931/05/202010635816
2030/06/20209716787
2131/07/202014408227
2231/08/202011919418
2330/09/2020110310521
2431/10/202088211403
2530/11/2020148012883
2631/12/2020138314266
Sheet1
Cell Formulas
RangeFormula
C3:C26C3=SUMIFS($B$3:$B$26,$A$3:$A$26,">="&DATE(YEAR(A3),1,1),$A$3:$A$26,"<="&A3)
 
Upvote 0
It is matrix math
(YEAR($A$3:$A$26)=YEAR($A3))*($A$3:$A$26<=$A3)), has two factors:
1. YEAR($A$3:$A$26)=YEAR($A3)
2. ($A$3:$A$26<=$A3)

when those conditions are true the matrix math give a number other than zero.
the filter function uses only the cells with non zero values from column A, and selects the cells in column B relative to those cells.
 
Upvote 0
Hi, that part is specifically restricting the filtered rows to those that are less than or equal to the date in column A for the row the formula is on.

SUMIFS() might be a little more efficient, but I doubt there's much in it either way.

Book1
ABC
1
2MonthAmountYTD
301/01/201912561256
428/02/201913692625
531/03/201910183643
630/04/201914065049
731/05/20199926041
830/06/201913647405
931/07/201914978902
1031/08/2019132210224
1130/09/2019104211266
1231/10/2019121412480
1330/11/201993913419
1431/12/2019128414703
1531/01/202010731073
1629/02/202014242497
1731/03/202012833780
1830/04/20209734753
1931/05/202010635816
2030/06/20209716787
2131/07/202014408227
2231/08/202011919418
2330/09/2020110310521
2431/10/202088211403
2530/11/2020148012883
2631/12/2020138314266
Sheet1
Cell Formulas
RangeFormula
C3:C26C3=SUMIFS($B$3:$B$26,$A$3:$A$26,">="&DATE(YEAR(A3),1,1),$A$3:$A$26,"<="&A3)

Okay thanks for explaining it further, the formula must be acting as some sort of counter, I think I like your formula more than mine.
 
Upvote 0
@tigerzen it doesn't act as a counter, the sumifs is also just like the filter criteria, behind the scenes it is using matrix math, and calculating TRUES and FALSES. and passing the value to include from the relative cells in the sum when all of the conditions are TRUE.
 
Upvote 0
@tigerzen it doesn't act as a counter, the sumifs is also just like the filter criteria, behind the scenes it is using matrix math, and calculating TRUES and FALSES. and passing the value to include from the relative cells in the sum when all of the conditions are TRUE.
Thanks awoohaw for clarifying.
 
Upvote 0

Forum statistics

Threads
1,215,016
Messages
6,122,700
Members
449,092
Latest member
snoom82

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