I want to write excel formula that will sumif the values based on a match of the rows. The problem is that I the cells to be matched can occur multiple times and basing on the Mapping legend they should return the sum of values.
In the yellow cells I am trying to caluclate sumif of values in range B9:B14. In formula I am using index to match the names and to return the sum of all that is assined to Item1, then Item2 and Item 3. Unfortunately, Index gives only the match with the first met not with the all that I have in mapping legend. Does Anybody has idea how to write this formula?
Here is the formula that I use (wrong) and in cell C4 and C5 is the result that should be achieved for Item 2 and Item 3:
:
Item 1 is ok because it does not have more than 1 mapping.
You can also use the following in B3 and drag down.
Enter as an array formula using Ctrl+Shift+Enter
=SUMPRODUCT(--($A$10:$A$15=IF($F$3:$F$8=$A3,$G$3:$G$8)),$B$10:$B$15)
This works because the arrays are of equal length and items appear in the same order.
You can easily accomplish this in two steps:
In H3 enter formula: =SUMIF($A$10:$B$15, G3, $B$10:$B$15). Drag it all the way down until 8th row.
In B3 enter formula: =SUMIF($F$3:$H$8, A3, $H$3:$H$8). Drag it all the way down until 5th row.
Your results should be like this:
its very simple no need to complicate with index functions.
First you need to cross ref the mapping legend with your inputs using sum-if function and then do that again to get individual values from each items.
Sumif in action
Sumif visualized
With refrence to the image put this formula in H3 to H8
=SUMIF($A$10:$A$15,G3,$B$10)
and then this formula in B3 to B5
=SUMIF($F$3:$F$8,A3,$H$3:$H$8)
Related
I have several lists of general categories in different columns, with each category title in row 1 and each having several different items in rows below it. Picture for reference:
On this same worksheet I want to be able to enter any of the items (Pork, Apple, Cheese, etc.) in cell E2 (my lookup value). What formula can I put in cell F2 to have it return the header of the list that item belongs to (Meat, Fruit, Dairy, etc.)? With my current understanding of V/HLOOKUP and INDEX/MATCH formulas I believe you can only lookup values in a single row or , but here I want to be able to have a lookup array of multiple rows and columns, and have it return the value of the top row of the appropriate column.
Edit:
Here is what I have tried so far:
=HLOOKUP(E2,A1:D5,1,FALSE)
=INDEX(A1:D5,1,MATCH(E2,A2:D5,0))
I am using Excel 2016
The answer is to use SUMPRODUCT.
If your lookup value is in E2 and your formula in F2, use this formula:
=INDEX(A1:D1,SUMPRODUCT((A2:D5=E2)*COLUMN(A2:D5)))
This formula is not an array formula, and doesn't require the ctrl+shift+enter.
=INDEX(A1:D1,,MIN(IF(E2=A2:D5,COLUMN(A:D))))
Enter the formula with ctrl + shift + enter
MIN searches for the first TRUE where E2=A2:D5 and returns in which column A:D that was and returns that number for use in your INDEX.
Having A1+C1 and B1+D1 in two cells how can I dynamically set up a formula to catch if some column is added.
Let's say the user adds two columns in the middle. I should have A1+C1+E1 and B1+D1+F1.
I thought it would have been automatic but it is not.
Replace:
=A1+C1
By:
=SUM(A1:C1) - B1
In case you want to check if the column number is divisble by three, you can use following formula:
=IF(MOD(COLUMN(A1);3)=0;A1;0) // I've put the values from 1 to 10 in A1-J1
// and I've dragged this formula from A2 to J2,
// the values were 0,0,3,0,0,6,0,0,9,0.
Unfortunately I don't have a simple way to sum those values in one easy formula.
If you always add two columns then A1+C1 will always be looking at odd number columns and B1+D1 will always be looking at even numbered columns.
{=SUM(IF(ISODD(COLUMN($A$1:$D$1)),$A$1:$D$1))}
and
{=SUM(IF(ISEVEN(COLUMN($A$1:$D$1)),$A$1:$D$1))}
As long as you insert columns between A:D the ranges will extend to accommodate.
Edit:
Based on the comment that row 2 contains codes and row 3 contains the figures to add up for each code then this array formula will work:
{=SUM(IF($A$2:$J$2="H1",$A$3:$J$3))}
Edit2: and if I wake up you can even use the non-array and built in formula:
=SUMIF($A$2:$J$2,"H1",$A$3:$J$3)
The H1 text can be changed to another code or to a cell reference containing the code to get the sum of values in row 3 for the specified code.
As an array formula it must be entered using Ctrl+Shift+Enter.
Let's say,
Sheet1:A1 = x
Sheet2 contents look like
x 3 3 4
y 0 2 1
Is there an excel formula that could match Sheet1:A1 with Sheet2:A1 (basically the value 'x') and add the other cells in that row (3,3,4). The result (Sum='10') should get updated at Sheet1:C4 lets say.
I tried SUMIF but that shows the content of only one column due to the restriction that it can handle only the matchable array size. I know this can be achieved through VBA, but just wanted to know if a formula is available.
TIA!
This formula will do what you want:
=SUM(SUMIF(Sheet2!A:A,A1,INDIRECT("Sheet2!" & {"B:B","C:C","D:D"})))
It will iterate through the columns doing individual SUMIF() on each and then adding the results.
If you want more columns or different change the address in the array to the columns desired.
Try the following
=SUM(IF(Sheet2!A1:A99=A1,Sheet2!B1:D99,0))
Note that this is an array formula, so it must be entered using Ctrl+Shift+Enter.
What this formula does is converts any rows on Sheet2 without x in column A to zeros in B:D and then sums what is left.
Similarly, you could use
=SUMPRODUCT((Sheet2!A1:A99=A1)*Sheet2!B1:D99)
and you wouldn't have to enter it as an array formula.
For a non-volatile, non-array formula, try this
=SUM(INDEX(Sheet2!B:D,MATCH(Sheet1!A1,Sheet2!A:A,0),))
I am referring to below my google spreadsheet
https://docs.google.com/spreadsheets/d/1dCfShenhV2j98q5wkOXMeyWj9tlMZbaBgBqB2vAPdHo/edit?usp=sharing
I am looking to update H,I and J columns using vlook formula in way that it should match both name and date values in my data range, which in A,B and C columns
Here is the issue I am facing with normal vlookup is that I can check only name.It is ignoring the date and updating the vlooked up data on all date column.
Eg: Alpha and date 20141120 value is 10, it should fill only H3, but it is updating, H3 I3 and J3 with value 10
I really appreciate your answer on this problem!!!
you can use this formula of index and match:
=IFERROR(INDEX($A:$C,MATCH(1,($A:$A=$G3)*($B:$B=H$2),0),3),"")
paste it in the first cell of your table H3, and drag and fill to the right and then select the entire row and fill down till end.
it should work.
if error(();"") : you will get empty cells if there is no match.
this is an array formula, so press ctrl+shift+enter to calculate the formula
UPDATE: here is [the example sheet downloadable from here}(https://www.dropbox.com/s/clqxsj5j4bdk27b/indexmatch.xlsx?dl=0)
Basically you need to concatenate the results, then use a VLOOKUP on that.
I.e. insert a column between B and C, with formula "=CONCATENATE(A2,B2)"
In the range you want to update, use the column and row headings for you lookup
"=VLOOKUP(CONCATENATE($g3,h$2),$c$1:$d$3,2,false)"
You want to perform a Multiple Lookup (see this).
As indicated there, enter
=IFERROR(LOOKUP(2,1/($A$1:$A$3=$G3)/($B$1:$B$3=H$2),$C$1:$C$3),"")
in H3. Copy into H3:J5.
This avoids array formulas.
I have a series of numbers
0,1,99,5,5,98,9
They are unsorted and will remain that way.
I cannot use macros.
I want the answer 89 from a formula or an array formula.
89 is the biggest gap (between 9 and 98) in this series when sorted.
I want a formula, no vba, and no sorting my column or row.
I need a formula that sorts the list and subtracts one cell relative to the sorted list and gives the largest difference of the list of differences it creates.
so the list becomes 0,1,5,5,9,98,99
subtracts the current from the previous (na,1,4,0,4,89,1)
and gives me the max 89.
My list is a column of 7 rows.
This formula must be array-entered. In the formula RNG refers to the range where you have entered your numbers, e.g. A1:A7
=MAX(LARGE(RNG,ROW(INDIRECT("1:"&-1+COUNT(RNG))))-
LARGE(RNG,ROW(INDIRECT("2:"&COUNT(RNG)))))
To array-enter a formula, after entering
the formula into the cell or formula bar, hold down
ctrl-shift while hitting enter. If you did this
correctly, Excel will place braces {...} around the formula.
You can see how the formula works by using the Evaluate Formula option on the Formula Auditing tab of the Formulas ribbon.
In brief, the formula works by creating two arrays, sorted in order of size. The "K" value of the LARGE function is an array created by the ROW(INDIRECT sequence. The first returns
{1;2;3;4;5;6}
and the second returns
{2;3;4;5;6;7}
The two arrays of values returned would then be:
{99;98;9;5;5;1}
{98;9;5;5;1;0}
Subtracting one from the other results an array of the differences, and we find the MAX.
MAX(A:A) - LARGE(A:A,2) gives the difference between the largest and second-largest value if your numbers are in column A. Don't put this formula in column A.
Place the values in A1 thru A7 in any order!
In B1 enter:
=RANK(A1,$A$1:$A$7,0)+COUNTIF($A$1:$A1,A1)-1
and copy down thru B7
In C1 enter:
=INDEX($A$1:$A$7,MATCH(ROW(),B$1:B$7,0))
and copy down thru C7
In D2 enter:
=C1-C2
and copy down thru C7
Finally in E1 enter:
=MAX(C:C)
Column B represents the order of the values in column A if they were sorted. Column C contains the values of column A in sorted order. Column D are the differences and E1 gives the desired answer. Here is an example: