index and match multple criteria - excel

I am trying to use index and match to find when two columns match another two columns then return another column in the same row. For example,
IF (Sheet1:ColA = Sheet2:ColA) and (Sheet1:ColB = Sheet2:Col B) then return Sheet2:ColC.
Here is what I have so far as my formula which does not work:
=INDEX('Sheet2'!C:C,MATCH(1,('Sheet1'!A1='Sheet2'!A1:A4)*('Sheet1'!B1='Sheet2'!B1:B4),0))
I want the "Wanted Col" values that are highlighted in the image.

Your formula seems correct, but it needs to be an Array formula. To achieve this; edit the formula through the formula bar and then press ctrl+shift+enter to set it as an array formula.
It should then look like this:
{=INDEX('Sheet2'!C:C,MATCH(1,('Sheet1'!A1='Sheet2'!A1:A4)*('Sheet1'!B1='Sheet2'!B1:B4),0))}
Alternatively, you can avoid using array formulas by adding a second index:
=INDEX(Sheet2!C:C;MATCH(1;INDEX((A1=Sheet2!A:A)*(B1=Sheet2!B:B);0;1);0))

If you have Office365 then you can use Filter() formula-
=FILTER(Shee2!$C$1:$C$4,(Shee2!$A$1:$A$4=A1)*(Shee2!$B$1:$B$4=B1))
Alternatively You can use INDEX() and SUMPRODUCT() together. Try below-
=INDEX(Sheet2!C:C,SUMPRODUCT(ROW(Sheet2!C:C)*(Sheet2!A:A=A2)*(Sheet2!B:B=B2)))

Related

Excel Formula - Criteria To Concatenate multiple cells by matching source cell

I am Looking to concatenates multiple cells into one by Index-matching the criteria
The below formula is not pulling in all the required UPCs against the specified criteria
=INDEX($B:$B,MATCH($D:$D,$A:$A,0))
I would like the end result to look like COL E2 in the below image with semi-colons in between every value ;
Any help here would be much appreciated.
If you have Office365 then use TEXTJOIN() with FILTER() function.
=TEXTJOIN(";",TRUE,FILTER($B$2:$B$15,$A$2:$A$15=D2))
Edit: Assuming you don't have access to O365 dynamic formulas. Then try below array formula.
=TEXTJOIN(";",TRUE,IF($A$2:$A$15=D2,$B$2:$B$15,""))
Press CTRL+SHIFT+ENTER to evaluate the formula as it is an array formula.
An alternative approach using the CONCAT function:
=CONCAT(FILTER(B:B, A:A=D2)&";")
Explanation:
The FILTER logic is just like Harun24HR suggested. Creating an array of all the values in B where the value in A is equal to D2.
The & operator works on each element in the array and adds a delimiter ";" to each value.
Finally, the CONCAT function combines all of the elements in the array into a single string.

How can I sum with partial parts of cells, when there are empty cells?

I have a range of data. Each cell contains a number and some text like this,
1*100KVA.
Now I want to sum the numbers before * . I have found functions like this one:
=SUMPRODUCT(1*(LEFT(V2:V30;FIND("*";V2:V30)-1)))
and this:
=SUMPRODUCT((VALUE(LEFT(V2:V30;FIND("*";V2:V30)-1))))
but they don't work, when there are empty cells in the range.
is there any solution?
try this:
=SUMPRODUCT(IFERROR(VALUE(LEFT(V2:V30;FIND("*";V2:V30)-1));0))
If you do not use Microsoft365 enter the formula with [CTRL]+[SHIFT]+[ENTER]
Here an example for Region A2:A5
A workaround non-array formula
Maybe by adding "0*" behind the data, and the formula become >>
=SUMPRODUCT(0+LEFT(A2:A5&"0*",FIND("*",A2:A5&"0*")-1))
Note : to replace comma with semicolon to suit with your regional setting

Lookup for 2nd, 3rd, ..nth match and return sorting results from smallest to largest values?

I have tried searching on google but I didn't find the solution yet.
I would like to lookup the value that match with conditions and return result with sorting from small to large. What formula should i use to do this?
Thank you very much.
If you have duplicate values in Time column, the following array formula can help :
{=IFERROR(SMALL(IF(($D2=$A$2:$A$12)*($B$2:$B$12>=TIME(7,0,0))*($B$2:$B$12<=TIME(10,0,0)),IF(COUNTIF($D2:D2,$B$2:$B$12)=0,$B$2:$B$12)),1),"")}
Array formula after editing is confirmed by pressing ctrl + shift + enter
I would use the SMALL function of Aggregate:
=IFERROR(AGGREGATE(15,6,$B$2:$B$10/
(($A$2:$A$10=$D2)*($B$2:$B$10>=TIME(7,0,0))*($B$2:$B$10<=TIME(10,0,0))),COLUMN(A1)),"")
To retrieve multiple matching values from a set of data with a formula, you can use the IF and SMALL functions to figure out the row number of each match and feed that value back to INDEX.
{=INDEX(array,SMALL(IF(vals=val,ROW(vals)-ROW(INDEX(vals,1,1))+1),nth))}
Where:
array: 1 column range containing the results -> Column: B:B
vals: 1 column lookup array -> Column: A:A
val: lookup value -> Column: D:D
nth -> Change row 1 values to 1,2,3,4 etc. instead of 1st, 2nd 3rd...
As always when working with array formulas, use ctrl+shift+enter instead of normal enter
If you have O365 with the UNIQUE function, you can use:
D2: =UNIQUE(Name) 'to generate the list of names
E2: =IFERROR(SMALL(FILTER(Name:Time,(Name=$D2)*(Time>=TIME(7,,))*(Time <=TIME(10,,))),COLUMNS($A:A)),"")
Select E2 and copy across and down

Passing multiple values to SUMIFS function in Excel

I have Twocolumns A, B ..I am trying to get the sum of A like below.
=SUMIFS(
sheet1!$A:$A,
sheet1!$B:$B, ("AB", "BC", "CD")
)
But this formula is not working.
Please suggest me.
Try to use following formula:
=SUMPRODUCT((sheet1!$B:$B={"AB","BC","CD"})*(sheet1!$A:$A))
or alternatively you can use an array formula:
=SUM(IF(sheet1!$B:$B={"AB","BC","CD"},sheet1!$A:$A,0))
enter formula in the formula bar and press CTRL+SHIFT+ENTER to evaluate it......
If I'm guessing your intention right, you should have:
=SUMIFS(sheet1!$A:$A,Sheet1!$B:$B,"AB")+SUMIFS(sheet1!$A:$A,Sheet1!$B:$B,"BC")+SUMIFS(sheet1!$A:$A,Sheet1!$B:$B,"CD")
Add two helper columns: in D:D you have the list of valid values. In C:C you have a formula like this (change ; to ,). In F1 you have your sum like this:
=SUMIFS($A:$A,$C:$C,FALSE)
Now you can add any number of valid criteria in column D:D.
You can use SUMIFS to return an array (one for each criterion) and then SUM to sum those, i.e.
=SUM(SUMIFS(sheet1!$A:$A,sheet1!$B:$B,{"AB","BC","CD"}))
This way retains the speed and efficiency of SUMIFS without needing repetition
If you have your criteria values in a range of cells you can simply reference the range, but use SUMPRODUCT to avoid "array entry"
=SUMPRODUCT(SUMIFS(sheet1!$A:$A,sheet1!$B:$B,Z2:Z4))
where Z2:Z4 contains the criteria
Note: in both of these SUMIFS does all the "heavy lifting" - SUM/SUMPRODUCT is used simply to sum the resulting array

Excel SUM and IF combine help

I have two columns of numbers. Both are 1 to 5. I want to count all the cells where the left column value equals the right column value AND the left column value equals a certain value.
I tried this:
=SUM(IF(W2:W13=X2:X13 AND W2:W13=4,1,0))
I've tried pressing Ctrl+Shift+Enter and it adds {} around the formula but that didn't help either.
I think it's the W2:W13 = 4 part that doesn't work
=COUNTIFS(W2:W13,"=4", X2:X13, "=4")
You can use the sumif() function:
SumIf( range, criteria, sum_range )
it will apply the criteria for each row in the range.
Edit: to count the matches, you can use sum_range = 1 or use the Countif() function suggested by Ben in his answer
Have you considered a third column (C) with the formula IF(A1=B1,1,0) and then summing that third column?
I'm not much of an Excel Expert, but didn't they craeted the COUNTIF(range, criteria) function for this?
Add a third column eg Z2:Z13 with this formula: IF(AND(W2=X2; W2=4); 1; 0)
Then sum that one.
I don't have Excel 2007. So here's how you can do it in Excel 2003:
=COUNT(IF((W2:W14=4)*(X2:X14=4),Y2:Y14))
Since you are looking for a specific value and the column next to it to be the same value, you can just compare both columns to the same value.
The trick to get this to work is after entering the formula you need to hit F2 to go into edit mode and then hit CTRL-SHIFT-ENTER which makes this formula an array formula. This will put {} around the entire formula. Without making this an array formula this formula won't work.
I found this information in the Excel help document titled Count how often a value occurs

Resources