Sum a range of data considering a range of criteria

quemuenchatocha

Board Regular
Joined
Aug 4, 2021
Messages
50
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Dear beast regards

I am working with some figures on the number of people in a country, classified according to sex. I want to carry out sums taking into account specific age groups, for example Men between 2 and 10 years old (Men_2 - Men 10).

Libro1
ABCDEFGHIJKLMNOPQRSTUV
1GENDERMen_0Men_1Men_2Men_3Men_4Men_5Men_6Men_7Men_8Men_9Men_10Men_11Men_12Men_13Men_14Men_15Men_16Men_17Men_18Men_19Men_20
2TOTAL389.339389.438389.552389.755390.127390.648391.370392.272393.584395.161397.190399.724402.697406.195410.047413.983417.904421.494424.678426.956427.880
3GENDERWomen_0Women_1Women_2Women_3Women_4Women_5Women_6Women_7Women_8Women_9Women_10Women_11Women_12Women_13Women_14Women_15Women_16Women_17Women_18Women_19Women_20
4TOTAL371.789371.891372.035372.283372.657373.224373.986374.956376.344378.044380.150382.719385.890389.509393.634398.101402.694407.236411.759415.629418.405
5
6SUMIFSSUM(SUMIF)SUMPRODUCT
7Men: 0 - 1205.110.857?
8Women: 0 - 1004.117.359?
Data
Cell Formulas
RangeFormula
B7B7=SUMIFS(B2:V2,B1:V1,"Men_0",B1:V1,"Men_12")
C7C7=SUM(SUMIF(B1:V1,{"Men_0";"Men_1";"Men_2";"Men_3";"Men_4";"Men_5";"Men_6";"Men_7";"Men_8";"Men_9";"Men_10";"Men_11";"Men_12"},B2:V2))
B8B8=SUMIFS(B4:V4,B3:V3,"Women_0",B3:V3,"Women_10")
C8C8=SUM(SUMIF(B3:V3,{"Women_0";"Women_1";"Women_2";"Women_3";"Women_4";"Women_5";"Women_6";"Women_7";"Women_8";"Women_9";"Women_10"},B4:V4))


I have tried with SUMIFS and SUMPRODUCT but I have not been successful in the calculation (I do not know in which aspects I am making mistakes), instead I have tried with SUM(SUMIF) and I have obtained a result, only that it is an operation that is quite extensive, since if I decide to incorporate a very long age range, I would have to write each one of the criteria in the formula, and this would be quite long.

Is there a simpler formula to perform this calculation?

I appreciate your valuable input and comments.

PST: I don't know if it is also possible to use the FILTER function, in order to get the same results as required.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
How about
Excel Formula:
=SUMPRODUCT((MID(B1:V1,FIND("_",B1:V1)+1,100)+0<=MID(A7,FIND("-",A7)+1,100)+0)*(B2:V2))
 
Upvote 0
How about
Excel Formula:
=SUMPRODUCT((MID(B1:V1,FIND("_",B1:V1)+1,100)+0<=MID(A7,FIND("-",A7)+1,100)+0)*(B2:V2))
Dear @Fluff thank you very much for your valuable information.

Now a doubt has arisen in my mind and that is, how could I apply the same formula if I want to modify the age range, that is, if I want to find the sum for the age ranges for men between 3 and 10 years old (E1:L1), or 4 and 9 years old (F1:K1) or 11 and 15 years old (M1:Q1), without taking into account (eliminating) the information recorded in cells A7:A8?

Since as you propose it, it takes the values from cell B1 (year 0) and I do not know how to modify it to change this lower limit for another one that I want.

Is there a way to enter these criteria manually in the formula, for example, something like:

Excel Formula:
=SUMPRODUCT((B1:V1)*(here enter the lower limit of the age range I am looking for <= the upper limit of the age range I am looking for)*(B2:V2)) ?

The only thing I can think of for now is to extract the digit of each of the corresponding cells from row 1 and add them in another row (for example row 5, cell B5) like this:

Excel Formula:
B5 = VALUE(MID(B2:V2,FIND("_",B2:V2)+1,100))

and once the results are obtained in row 5, apply the SUMPRODUCT function in cell B6, for example, for the age range between 3 and 10 years old like this:

Excel Formula:
B6 =SUMPRODUCT((B5:V5)*(3 <= 10)*(B2:V2)) = 3.140.107

Obviously, the above formula, as I put it, does not give the correct result.

I hope you understand what I am looking for, and that I am not being somewhat confusing in my explanation.
 
Upvote 0
Hi,

Slightly modify your set up like I show in A6:D8
Enter whatever age range in B7:C8, the SUMPRODUCT will output result accordingly.

Book3.xlsx
ABCDEFGHIJKLMNOPQRSTUV
1GENDERMen_0Men_1Men_2Men_3Men_4Men_5Men_6Men_7Men_8Men_9Men_10Men_11Men_12Men_13Men_14Men_15Men_16Men_17Men_18Men_19Men_20
2TOTAL389339389438389552389755390127390648391370392272393584395161397190399724402697406195410047413983417904421494424678426956427880
3GENDERWomen_0Women_1Women_2Women_3Women_4Women_5Women_6Women_7Women_8Women_9Women_10Women_11Women_12Women_13Women_14Women_15Women_16Women_17Women_18Women_19Women_20
4TOTAL371789371891372035372283372657373224373986374956376344378044380150382719385890389509393634398101402694407236411759415629418405
5
6GenderAge fromAge toTotal
7Men3103140107
8Women492249211
Sheet1070
Cell Formulas
RangeFormula
D7D7=SUMPRODUCT((MID(B1:V1,FIND("_",B1:V1)+1,9)+0>=B7)*(MID(B1:V1,FIND("_",B1:V1)+1,9)+0<=C7)*B2:V2)
D8D8=SUMPRODUCT((MID(B3:V3,FIND("_",B3:V3)+1,9)+0>=B8)*(MID(B3:V3,FIND("_",B3:V3)+1,9)+0<=C8)*B4:V4)
 
Upvote 0
If you want to hard code the age range you can do it like
Excel Formula:
=SUMPRODUCT((MID(B1:V1,FIND("_",B1:V1)+1,100)+0>=0)*(MID(B1:V1,FIND("_",B1:V1)+1,100)+0<=12)*(B2:V2))
 
Upvote 0
Hi,

Slightly modify your set up like I show in A6:D8
Enter whatever age range in B7:C8, the SUMPRODUCT will output result accordingly.
Dear Mr. @jtakw, thank you very much for your valuable information and collaboration, is what I'm looking for, you gave me several ideas to modify the formula and adjust it to my needs and required results, a big hug!
 
Upvote 0
If you want to hard code the age range you can do it like
Excel Formula:
=SUMPRODUCT((MID(B1:V1,FIND("_",B1:V1)+1,100)+0>=0)*(MID(B1:V1,FIND("_",B1:V1)+1,100)+0<=12)*(B2:V2))
Dear @Fluff, as always your help is very useful and practical, thank you for answering my questions and providing solutions to my concerns, big hug!
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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