Excel compare two tables and return value - excel

I have two sheets as below in Sheet-4 if NE and Slot column match the Sheet-1 column which is AB1S2a SLOT-1 then i want the result SN which is in sheet-4 SN=CAT1016127B to be printed in Sheet -1 beside the slot, Is there any way?
Sheet-4:
Sheet-1:

Assume in Sheet1 cell D2 you want serial no. Then use this array formula to achieve that.
=IFERROR(INDEX(Sheet4!C:C,MATCH(B2&C2,Sheet4!A:A&Sheet4!B:B,0)),"")
As it is a array formula. Press CTRL+SHIFT+ENTER to evaluate the formula.

You could try the following code:
=SUMIFS(Sheet4!C:C;Sheet4!A:A;B2;Sheet4!B:B;C2)

Related

Count number of occurrences of a string in a cell range matching column and row headers

I have the following two tables in MS Excel.
I want to count the number of occurrences of 'AB' in the rows of 'Adam' and in the columns of 'Feb' and place in P2 cell.
Index and Match commands used as follows returns 'AC'. What is the best way to solve this?
=INDEX($B$3:$L$12,MATCH($N$2,$A$3:$A$12,1),MATCH($P$1,$B$1:$L$1,1))
Here is the file.
Try
=SUM(($B$3:$L$12=$O2)*($B$1:$L$1=$P$1)*($A$3:$A$12=$N$2))
may need array-entering pre Excel 365.
Have you tried using the SUMPRODUCT Function, it does not require CTRL SHIFT ENTER, so just copy the formula from here and paste it in the cell P2 and Fill down and fill across.
=SUMPRODUCT(($N$2=$A$3:$A$12)*($O2=$B$3:$L$12)*(P$1=$B$1:$L$1))

How to use comma separated values in a cell, as parameters in formula (PivotTable specifically)?

I have a formula that pulls data from PivotTable and sums up according to ID:
=SUM(GETPIVOTDATA("Value",$A$3,"AccounID",{5637855, 6839652, 5839670}))
I would like to use the same formula but with a reference:
=SUM(GETPIVOTDATA("Value",$A$3,"AccounID",A1))
When A1 is: 5637855, 6839652, 5839670.
In this case if there is one ID or 10 IDs - it will be the same formula and I can only add an ID in the cell A1.
I am sure that it is possible somehow with Macro, but I want a simple way (since macros in my company are restricted).
I found a few workarounds with SUMPRODUCT and range of cells, but this solution is not practical in my case.
Use this array formula
=SUM(IFERROR(GETPIVOTDATA("Value",$A$3,"AccounID",TRIM(MID(SUBSTITUTE($A$1,",",REPT(" ",99)),(ROW($A$1:INDEX(A:A,LEN($A$1)-LEN(SUBSTITUTE($A$1,",",""))+1))-1)*99+1,99))),0))
Being an array formula it needs to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.
All the A1 refer to the cell in which the string is found, EXCEPT the first one in the ROW argument. Leave that as A1 change all the others to the cell in which the string can be found.
Try this:
Option2:
if someone doesn't have the cell A1 restriction`
Create a table (use format as table) with the IDs you want to sum:
[criteria]
| 5637855|
| 6839652|
| 5839670|
Then replace in your formula with the range from your table criteria like:
=SUM(GETPIVOTDATA("Value",$D$1,"AccounID",Table1[criteria]))
and activate the formula as an array with Ctrl+Alt+Enter or Ctrl+Shift+Enter depending your Excel version.
If you highlight Table1[criteria] in the formula and press F9 you will see that the value it is getting is {5637855, 6839652, 5839670}.

Excel CountIf Formula With OR

I was looking for a excel formula to do a task. Tried using Countif,Countifs. But with no luck. Any help is appreciated.
Task as below.
Type--------------Primary Color--------------Secondary Color
Car----------------Blue--------------------------Red
Bike--------------Black-------------------------White
Car---------------Blue--------------------------Blue
I need a formula which gives me a count of Cars having blue as their colour(Either Primary Or Secondary)
You can use following array formula (confirmed with Ctrl+Shift+Enter to calculate count of blue cars:
=SUM(N((B2:B4="Blue")+(C2:C4="Blue")>0)*(A2:A4="Car"))
or non array version:
=SUMPRODUCT(N((B2:B4="Blue")+(C2:C4="Blue")>0)*(A2:A4="Car"))
This part:
(B2:B4="Blue")+(C2:C4="Blue")>0
is an alternative way of expressing OR (not suitable for array formulas as it always returns a single value). N function converts boolean values to 0 and 1.
Edit: updated the formulas to include condition for A column.
What about adding a column with the following
=IF(OR(B1="Blue", C1="Blue"), 1, 0)
and copy that down.
On another sheet you can sum that new entire column with
=SUM(D:D)
Of course you will have a worksheet reference to the other sheet attached to the SUM formula.
If you don't want to do an array formula you can just do 2 countifs formulas (which are easier for people to read than array formulas)
=COUNTIFS(b8:b12,"Blue")+COUNTIFS(c8:c12,"Blue")

Excel INDEX and MATCH Get Value

I have an excel workbook that I need some help with INDEX and MATCH or any other Formula that can get me my end result.
Here is sheet1:
SIT_ID METER SUSE_CD
10834282 DT0061 B
10834282 AW7931 P
21676286 CQ9635 P
21676286 DP4838 B
21726281 AW7880 P
21726281 DT0032 B
Here is Sheet2:
Site ID B P
10834282
21676286
21726281
Ultimately what I am trying to do is on Sheet2 is put the Meter that = B for the SITEID in the column and then Put the Meter that = P in the Same row.
I have never used Index or Match and I looked it up online but I am confused and hoping someone can help me with the correct formula or point me in the right direction.
Thanks so much!
INDEX first takes a range, then a row number, an optional column number (and an optional area number).
MATCH takes a value to lookup, an array and a mode.
In your problem you can use the following in Sheet2 cell B2:
=INDEX(Sheet1!$B$2:$B$7, MATCH($A2, IF(Sheet1!$C$2:$C$7=B$1,Sheet1!$A$2:$A$7), 0))
This formula is an array formula and will work with Ctrl+Shift+Enter and then you can fill it to the other cells.
I had to use an IF because there're two conditions to check.
EDIT: Use this one if your cell formats are different:
=INDEX(Sheet1!$B$2:$B$7,MATCH($A2*1,IF(Sheet1!$C$2:$C$7=B$1,Sheet1!$A$2:$A$7*1),0))
EDIT2: Adding trimming:
=INDEX(Sheet1!$B$2:$B$7,MATCH($A2*1,IF(TRIM(Sheet1!$C$2:$C$7)=TRIM(B$1),Sheet1!$A$2:$A$7*1),0))
EDIT3: If you're using it on your full data, change the range:
=INDEX(Sheet1!$B:$B,MATCH($A2*1,IF(TRIM(Sheet1!$C:$C)=TRIM(B$1),Sheet1!$A:$A*1),0))
Assuming your Sheet1 looks like this:
And your Sheet2 looks like this:
The formula in Sheet2 cell B2 and copied over and down to cell C4 is:
=INDEX(Sheet1!$B$2:$B$7,MATCH(1,INDEX((Sheet1!$A$2:$A$7=$A2)*(Sheet1!$C$2:$C$7=B$1),),0))
Note that this is a regular formula, so no need for Ctrl+Shift+Enter
A helper column D is added to initial columns.
D2: =$A2 & $C2
Now it's possible to make a simple search of the concatenated SITE_ID and SUSE_CD:
H2: =MATCH($G2&" B";$D$2:$D$8;0)
The result would be a row number (=1 in this case) for the needed string in array $D$2:$D$8.
INDEX shows the value of the cell, found by counting n-th row (defined by MATCH) and m-th column (=2) in array $A2:$A$8 from the upper left cell (A2).
Altogether: =INDEX($A$2:$B$8;MATCH($G2&" B";$D$2:$D$8;0);2)
The easiest way to get around with this is,
to use concatenation operator in the match function.
Don't forget to use Ctrl+Shift+Enter
Use below formula in column B of Sheet 2
{=INDEX(Sheet1!$B:$B,MATCH(Sheet2!$A2&Sheet2!$B$1,Sheet1!$A:$A&Sheet1!$C:$C,0))}
And the below formula in column C of Sheet 2
{=INDEX(Sheet1!$B:$B,MATCH(Sheet2!$A2&Sheet2!$C$1,Sheet1!$A:$A&Sheet1!$C:$C,0))}
And then flash fill the remaining rows.

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