Subtotals grouped by value using COUNTIF to create ranges for SUMIF, but in a single formula - excel-formula

End-goal: A column with the subtotals of groups (defined in the below table as all foods listed above Zucchini, incl Zucchini).
Current attempt: create a column to define groups using COUNTIF('count all 'zucchini' thus far'). Then use SUMIF to get the total cost for the current group.
Problem: I don't know how to do this without the COUNTIF column (since SUMIF needs range C:C to be resolved first). I'd like to have it in a single formula. I looked into array formulas but not sure if/how to apply that here.
FOOD COST COUNTIF(A2:A$2;"Zucchini") SUMIF(C:C;C2;B:B)
Apple 3 0 12
Pecan 7 0 12
Zucchini 2 0 12
Apple 4 1 23
Olive 8 1 23
Pecan 6 1 23
Zucchini 5 1 23
Apple 4 2 16
Olive 9 2 16
Zucchini 3 2 16
Any ideas on how to solve either the current problem or the end-goal problem? Thanks!

Put this in C2 and copy down:
=IF(A2="Zucchini",SUM($B$1:B2)-SUM($C$1:C1),"")
It basically sums everything to the row and subtracts what is already accounted for.

Related

Is there a way to find the closest row match based on a different row match?

I'm working with a data in which there are multiple sets of information in the same column. This is making it difficult to pick out the data I need as it always returns the first result. I am trying to find a way to ensure that the column result returned in a search is based on a different column's value. For example:
Name/Date
01/01/2022
02/01/2022
03/01/2022
04/01/2022
05/01/2022
Bob
1
7
2
6
1
Jane
1
7
9
3
1
Jimmy
8
7
5
4
2
Robin
1
2
9
6
2
Batman
4
7
6
6
8
06/01/2022
07/01/2022
08/01/2022
09/01/2022
10/01/2022
Bob
4
1
4
2
12
Jane
6
21
9
3
1
Jimmy
8
2
5
4
2
Robin
8
5
0
6
2
Batman
5
5
6
6
8
If I wanted to yield the number for Jane on 07/01/2022 (which is 21), is there any way of returning this? I've been able to use =MATCH to pull the correct column based on the date search criteria, but I cannot see a viable way of pulling for a particular person when their name appears multiple times in the same column. Attempting a lookup will return the first result for the name hit (so in the case of my Jane example, it would return row 3 instead of 9). I'm looking to be able to enter a name and a date, and it returns the result from that part of the array.
Is such a thing possible, please? If not, is there any workaround that may help to provide me the same result?
Thanks in advance for your assistance!
This is being attempting in Office 365.
Assuming:
ms365 (specifically access to the BETA-channel);
Equal intervals with the same names at the same postions;
Formula in I4:
=LET(X,WRAPCOLS(TOCOL(B1:F12,,1),6),SUM((A1:A6=I3)*FILTER(X,TAKE(X,1)=I2)))
Assuming your data starts in row 1
A1:F12 - data range
B17 - Jane
B18 - 07/01/2022
=LET(data,A1:F12,names,A1:A12,lookupname,B17,lookupdate,B18,INDEX(data,MIN(LET(rowlist,IF(names=lookupname,ROW(names),0),IF(rowlist>MAX(IF(data=lookupdate,ROW(data),0)),rowlist,""))),MAX(IF(data=lookupdate,COLUMN(data),0))))

How to combine SUMPRODUCT with an INDEX and MATCH formula?

Note, I have edited my original question to clarify my problem:
As the title suggests, I am looking for a way to combine the SUMPRODUCT functionalities with an INDEX and MATCH formula, but if a better approach exists to help solve the problem below I am also open to it.
In the below example, imagine that the tables are on different sheets. I have a report that has the sales of each ID in the rows and each month in the columns (first table). Unfortunately, the report only has IDs and not the region they belong to, but I do have a look up table which labels each ID with their respective region (second table):
A
B
C
D
1
ID
January
February
March
2
1
10
5
20
3
3
5
5
10
4
7
0
10
5
5
14
10
25
5
6
25
5
10
10
7
27
10
10
10
8
44
5
5
5
A
B
1
ID
Region
2
1
East
3
3
East
4
7
Central
5
14
Central
6
25
Central
7
27
West
8
44
West
My goal is to be able to aggregate the sales by region as per the result below. However I would only like to show sales data that belong to the month that is shown in cell D2.
Goal:
A
B
C
D
1
Region
Sales
February
2
East
10
3
Central
45
4
West
15
I have used the INDEX and MATCH combination to return a single value, but not sure how I can return multiple values with it and aggregate them at the same time. Any insight would be appreciated!
You may just use:
=SUMPRODUCT((Sheet1!B$1:D$1=D$1)*(Sheet1!H$2:H$8=A2),Sheet1!B2:D8)
Remember, SUMPRODUCT() could be quite heavy processing huge data, therefor to combine INDEX() and MATCH() is not a bad idea, but let's do it the other way around and nest the latter two into SUMPRODUCT() instead =):
=SUMPRODUCT(INDEX(Sheet1!B$2:D$8,0,MATCH(D$2,Sheet1!B$1:D$1,0))*(Sheet1!H$2:H$8=A2))
Another option using SUMIF+INDEX+MATCH function as in
In "Sheet2" B2, copied down :
=SUMIF(Sheet1!H:H,A2,INDEX(Sheet1!B$1:D$1,MATCH(D$2,Sheet1!B$1:D$1,0)))

Excel using SUMIF to calculate totals of multiple columns

I'm trying to use Excle's SUMIF to calculate totals of Col1 to Col5 for dates that are similar.
My formula is as follows =SUMIF($A2:$A7,A10,$B2:$F7), but this only gives me the total of a single column.
How can I get the Totals of all the columns based on the date like I've shown in my results.
Date Col 1 Col 2 Col 3 Col 4 Col 5
1/5/2017 1 2 2
1/5/2017 5 3 1
1/5/2017 9 5 5
2/5/2017 10 5 3
2/5/2017 20 10 3
2/5/2017 6 8 1 5
Desired Results
1/5/2017 15 7 7 3 1
2/5/2017 30 11 11 11 8
use below formula in cell B11
=SUMIF($A$2:$A$7,$A11,B$2:B$7)
Per the example you provided, One solution is to use SUMPRODUCT
Multiplies corresponding components in the given arrays, and returns the sum of those products
Microsoft Docs give a thorough example, but per SO etiquette, here is an example in case of link-rot: [FYI, I used absolute reference for easier filling across, arbitrary how you get it done though]
Forumlas shown:
Formula is kind of hard to see without clicking on image:
=SUMPRODUCT(($B$3:$B$8=$B$11)*C3:C8)
This basically breaks down like this, it searches the B:B column for a match, and it will naturally return a true or false for the match, or 0/1 counterparts, and multiplys that by the number found in the column to the right (C3:C8), so it will either be 1 * # = # or 0 * # = 0

Sum of Vlookups advice

I have a column "Uni"
E.g.
Person Uni Round 1 Round 2 Total Rank
Leia Notts 5 5 10
Hailey Notts 6 5 11
Bobby Bath 8 1 9
James Liverpool 9 1 10
Then another table:
University Total Score Rank
Notts =sum(vlookup(...))
Bath =sum(vlookup(...))
Currently, my formula returns the 'first' lookup of the keyword - e.g. for notts, it returns '10' - rather than looking up the 10 and the 11 and summing them.
How do I make it lookup and sum both values?
My current formula is =sum(vlookup(S7,B$3:Q$40,15,FALSE)) where S7 is "Notts", range, index column 15 is "total score"
There's about 8-10 of each university.
Vlookup only returns one value, you can't sum over that.
Maybe use instead something like
=SUMIF(B$3:B$40,S7,$P3:$P40)

Excel ranking based on grouping priorities

Hi everyone I have an excel question on how to rank but based first on a a ranking but then next on a second priority of a group. The formula is written in column 'Final_Rank' and I just hid a bunch of rows to show the clear example. Within the column Rank is just a normal rank function. I want the priority to be within Rank first, but then to add the next rank to the next item of the same group*. So if you look at Group HYP it will supersede ranked (3 and 4) and then 5 would be given to the next newest group.
I hope this is a clear explanation, thanks.
Group Rank Final_Rank_Manual
TAM 1 1
HYP 2 2
GAB 3 5
HYO 4 8
ALO 5 9
HYP 7 3
ACO 8 12
IBU 9 13
ACO 11 14
ALO 18 10
GAB 44 6
IBU 53 15
IBU 123 16
GAB 167 7
HYP 199 4
You can do this with an extra helper column. Assuming your table currently occupies columns A-C, with one header row, put the following in C2:
=SMALL(IF($A$2:$A$6=A2,$B$2:$B$6,9999999999),1)+(B2*0.000000001)
You'll need to enter this as an array formula by using Ctrl+Shift+Enter↵. Copy it down throughout the whole column. This gives you the group's ranking, and it adds a tiny decimal indicating the individual values position within each group. (e.g. the 3rd "HYP" value is converted to something like 2.0000000199, because out of all the available values, the second lowest belongs to "HYP", and this specific "HYP" value is 199).
Next, enter the following in D2 and copy it down throughout the column:
=RANK(C2,$C$2:$C$6,1)
This will give you the "Final" rankings. There won't be any ties because of the tiny decimals we added in the previous formula. The results end up looking just like your sample.

Resources