Count and sum all, or according to weeknumber and year, or year only if specified

rovius

New Member
Joined
Dec 14, 2019
Messages
2
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
I have sheets with this data (simplified for the example):
range A1:A10 = dates
range B1:B10 = items to count
range C1:C10 = items to sum

and I have two reference cells:
D1 = week number
D2 = year

I have used
one formula to count:
1) to count the whole column B range if no week number is specified in D1 (D1 is blank)
2) and to count the column B data for a specified week number if a week number is present in D1
=IF(ISBLANK(D1);COUNTA(B1:B10);SUMPRODUCT(--(WEEKNUM(A1:A10+0;2)=D1)+0;--(B1:B10<>"")))

and another formula to sum:
1) to sum the whole column C range if no week number is specified in D1 (D1 is blank)
2) and to sum the column C data for a specified week number if a week number is present in D1
=IF(ISBLANK(D1);SUM(C1:C10);SUMPRODUCT(--(WEEKNUM(A1:A10+0;2)=D1)+0;C1:C10))

Now my data has accumulated over one year, and I need to modify my two formulas so that they would:
1) count and sum according to week number and year, if specified in D1 and D2
2) count and sum according to year only, if specified in D2 (and D1 is blank)
3) count and sum the whole range, if no week number and year are specified (D1 and D2 are blank)
and still not using helper columns

Thanks in advance for all replies!
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Try this, (I hope to find a shorter formula ...)


Book1
ABCDEF
101/01/201911CountSum
202/01/2019022019837
303/01/201913
404/01/201904
505/01/201915
606/01/201916
707/01/201927
808/01/2019
909/01/201929
1010/01/2020210
Sheet
Cell Formulas
RangeFormula
E2E2=IF(D1="",IF(D2="",COUNTA(B1:B10),SUMPRODUCT((B1:B10<>"")*(YEAR(A1:A10+0)=D2))), IF(D2="",SUMPRODUCT((B1:B10<>"")*(WEEKNUM(A1:A10+0,2)=D1)), SUMPRODUCT((B1:B10<>"")*(WEEKNUM(A1:A10+0,2)=D1)*(YEAR(A1:A10+0)=D2))))
F2F2=IF(D1="",IF(D2="",SUM(C1:C10),SUMPRODUCT((C1:C10<>"")*(YEAR(A1:A10+0)=D2)*(C1:C10))), IF(D2="",SUMPRODUCT((C1:C10<>"")*(WEEKNUM(A1:A10+0,2)=D1)), SUMPRODUCT((C1:C10<>"")*(WEEKNUM(A1:A10+0,2)=D1)*(YEAR(A1:A10+0)=D2)*(C1:C10))))
 
Upvote 0
Another options, but array formulas

{=SUM((B1:B10<>"")*(IF(D2="",1,YEAR(A1:A10)=D2))*(IF(D1="",1,WEEKNUM(A1:A10+0,2)=D1)))}


{=SUM((C1:C10<>"")*(IF(D2="",1,YEAR(A1:A10)=D2))*(IF(D1="",1,WEEKNUM(A1:A10+0,2)=D1))*(C1:C10))}


Array formulas
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself.
 
Upvote 0
Thank you so much DanteAmor, I'm really grateful!
Both the regular and array formulas are working perfectly!
I will use the array formula which is impressively short and powerfull
 
Upvote 0
Hi @rovius, by the way, welcome to the board!

I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,444
Messages
6,124,891
Members
449,194
Latest member
JayEggleton

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