Assign values by matching two lists in excel - excel

I have these two list and I am trying to assign values i.e 11,22,33 to the second list that matches values with the first list.
So, for examples in the second list if its "Industrials" it would take value of 11, "Resources" would take value of 33 and so on.
I have tried index match but I believe it won't work in this case. Any help or ideas would be great.

So you may try using any one of the following formulas as shown in the image below
APPROACH ONE - FORMULA USED IN CELL E2
=INDEX($B$2:$B$8,MATCH(LEFT($D2,3)&"*",$A$2:$A$8,0))
APPROACH TWO - FORMULA USED IN CELL F2 (O365 & EXCEL 2021)
=XLOOKUP(LEFT($D2,3)&"*",$A$2:$A$8,$B$2:$B$8,,2)
APPROACH THREE - FORMULA USED IN CELL G2
=VLOOKUP(LEFT($D2,3)&"*",$A$2:$B$8,2,0)
APPROACH FOUR - FORMULA USED IN CELL H2
=LOOKUP(2,1/(LEFT(D2,3)=LEFT($A$2:$A$8,3)),$B$2:$B$8)

Related

Countifs using multiple dynamic arrays as criteria

I have a countifs formula that seems to be letting me down.
It's using 2 different criteria and both are dynamic arrays - here represented by the cell ref and the hashtag:
COUNTIFS(A:A,B1#,C:C,D1#)
The dynamic arrays in cells B1 and D1 are working fine, and if I change the countifs so only 1 of the criteria refers to a dynamic range (removing the hashtag and selecting 1 of the results in the array) then it works fine. The problem is when I need it to use 2 (or more?) dynamic ranges.
Any thoughts?
if the items are independent of each other as in B1 does not directly correlate to D1 and B2 directly correlates to D2 then you need to Transpose one of the arrays.
=COUNTIFS(A:A,B1#,C:C,TRANSPOSE(D1#))
Note:
This will create a 2D array with as many rows as in B1# and as many Columns as in D1#. So to get the total wrap it in SUM or SUMPRODUCT.
Also, The max independent arrays are two.
Also that it is an AND situation so the value in A must be equal to the a value in B and the value in C in the same row, must be equal to a value in D
If one wants more than two we need to move away from countifs and use array type formula which will require the use of ranges that encompass the most rows that would be used and not full columns.
=SUMPRODUCT(ISNUMBER(MATCH(A1:A100,B1#,0))*ISNUMBER(MATCH(C1:C100,D1#,0)))
This version is AND like the COUNTIFS where the values in A and C on the same row must exist their corresponding lists to be counted. IF you want to count them individually then change the * to + which makes it an OR.
And the use of ISNUMBER(MATCH(A1:A100,B1#,0)) can be added as many as desired changing the ranges as necessary.
Edit: This will not work, see below comment by #Scott Craner
I'm unsure if COUNTIFS work well with dynamic arrays, which is what you are currently using.
A workaround can be to try use SUMPRODUCT
=SUMPRODUCT((A:A=B1#)*(C:C=D1#))

Excel: Compare two values to another two values to return the adjacent value

In excel, I am trying to compare two values to another two values that are in different columns. If they all match then it should copy the value on the adjacent column (In this case it's the third one), but I'm not finding any articles or websites explaining how to do it. You can find the formula that I am using below:
=IFERROR(VLOOKUP(AND(MATCH(A$2:A$22=F$1;A$2:B$22;0);MATCH(B$2:B$22=E2;A$2:B$22;0));A$2:B$22;3);"error")
Note: The values in the first and second columns may differ (example: instead of the first floor I can have the ground floor). I need a formula that can be dynamic depending on the values that are inserted in those cells/columns/rows.
Can any of you help me?
You can use a LOOKUP construct like below in cell F2 to be copied down and across.
=IFERROR(LOOKUP(2,1/(($A$2:$A$22=$E2)*($B$2:$B$22=F$1)),$C$2:$C$22),"")
Note- Argument separator is comma for me which is semi-colon for you.
In F2 try:
=IFERROR(LOOKUP(2,1/(($A:$A=$E2)*($B:$B=F$1)),$C:$C),"")
And drag down and right.
Or, if you don't care about false 0s:
=SUMIFS($C:$C,$A:$A,$E2,$B:$B,F$1)

Excel - How to count the number of distinct texts of a specific date inside a table?

I'm trying to count the number of distinct text from a specific date in a data table.
Data Sample with expect result :
I was able to figure out how to count the distinct element from a range I specify, because I can determine the first and last row containing the date.
=SUMPRODUCT(1/COUNTIF(B2:B15,B2:B15))
I have tried to modify my formula so that it determines the cell range by itself but without success.
I searched for an answer, using a combination of CELL and MAXIFS, example below, but Excel does not accept the formula.
=CELL("row",MAXIFS(A2:A15,A2:a15,D2))
I've looked at the INDEX formula, but I can't figure out how to do what I want to do. 😑
Any idea what I'm doing wrong, or what I should be doing instead?
Thanks, I appreciate it!
If you have Office 365 and the new Dynamic Arrays, this sort of formula has become ridiculously easy.
This formula in cell E3:
=COUNTA(UNIQUE(FILTER($B$2:$B$15,$A$2:$A$15=D3)))
Copy down.
You can also generate the unique list of dates with this formula in D3, which spills down automatically and does not need to be copied.
=UNIQUE(A2:A15)
It wasn't easy, but by separating each step of the problem, I was able to solve it.
Note that my solution only works because my dates are sorted.
Here's the final formula in the cell "One formula to rule them all":
=SUMPRODUCT(1/COUNTIF(INDIRECT(CONCATENATE(ADDRESS((MATCH(D3,$A$2:$A$15,0)+1),2),":",ADDRESS(MAX(($A$2:$A$15=D3)*ROW($A$2:$A$15)),2))),INDIRECT(CONCATENATE(ADDRESS((MATCH(D3,$A$2:$A$15,0)+1),2),":",ADDRESS(MAX(($A$2:$A$15=D3)*ROW($A$2:$A$15)),2)))))
Here are my explanations of my process:
Formula if I select the range :
=SUMPRODUCT(1/COUNTIF(B2:B15,B2:B15))
Formula to get the first iteration
=ADDRESS((MATCH(D3,$A$2:$A$15,0)+1),2)
Formula to get the last iteration
{=ADDRESS(MAX(($A$2:$A$15=D3)*ROW($A$2:$A$15)),2)}
Create range from two addresses
=INDIRECT(CONCATENATE(F3,":",G3))
Formula giving me the expect result
=SUMPRODUCT(1/COUNTIF(INDIRECT(CONCATENATE(F3,":",G3)),INDIRECT(CONCATENATE(F3,":",G3))))

Exact same CountIf formula giving different results from different cells

I saw an solution where someone was using a range as the criteria for COUNTIF and while trying to understand it better I found some really odd things happening and hoping someone could explain to me what is going on. Here is the setup of the excel.
Name,,Name
Excitebike,,Excitebike
RC Pro Am,,Super Mario Brothers
Punch Out,,Duck Hunt
Super Mario Brothers
Duck Hunt
Hopefully you can use the above to copy and paste it in. In column A there is a list of names and in column C there is a list of some of the names. In cell E1 there is a formula:
=COUNTIF($C$2:C4,$A$2:$A$6)
Then in cell E2 there is the exact same formula.
=COUNTIF($C$2:C4,$A$2:$A$6)
Here is a screen shot so you can see the formulas are identical:
So cell E1 and E2 have the exact same formula but are giving me a different result. As you can see in the first screen shot cell E1 gives a result of 0 while E2 gives a result of 1. Then if I make cell E1 into an array formula it gives a result of 1.
Why would the exact same formula in two different cells give a different result and why when changing cell E1 to an array formula would it change the result? I am using Excel 2016.
UPDATED: Additional questions.
When passing in a array into COUNTIF does it check each element in the range against each element in the criteria or does it just check row in the range against the corresponding row in the criteria?
Even when I put them in the same order, I cannot get the COUNTIF to return a number greater then 1. I would expect if the first 3 match the COUNTIF should return 3 but it is returning 1 for me. Please see below:
While rows 2, 3 and 4 match it is still giving an answer of 1.
I was a little surprised this worked at all. Typically I've used the "criteria" as >4 or <10 etc. Nice to know you can do a string comparison at all.
When using CountIf outside of an array formula you're going to be getting a comparison of values in adjacent cells. Typically CountIF is looking for a single criteria, not a range. At least that's the way I've always used it. eg, first formula in the cell range compared to first cells in each of the cell ranges.
Try these two experiments. Copy Super Mario Brothers from the right column to the left column and the results are going to now show 1 and 1 in the two formulas. Put it back. Move the two cells you have formulas in down one row, and you should see the results go from 1 and 0 to 1 and 1. Move it one more cell lower and it changes the values again.
I'm not sure this is what you're trying to accomplish, but copy this into the formula at and then copy down 6 rows. =COUNTIF($A$2:A$6,C2)

Count occurrences of values in a specific range (Excel) (no VBA)

I need to count all of the occurrences of a given value from a specific range of cells (containing strings or numbers), depending on a parameter stored in another cell.
I prepared a simple Excel table as an example (see attached image): let's say I want to count all of the occurrences of the VALUE "4" for the BASE "100". The result should be: 2 (C4 + C5).
Attached image
I tried to use COUNTIFS and FIND functions but with no results. The former only considers exact values (so the 4 in cell C5 will be ignored) while I seem to be unable to add another condition - the BASE column - to the latter.
Fact is I need to solve this with formulas only, no programming.
Thanks in advance for your help!
Use the SUMPRODUCT:
=SUMPRODUCT(($B$2:$B$10=100)*(ISNUMBER(SEARCH(4,$C$2:$C$10))))
There's a couple of other approaches, the simpler one is just to add another column which identifies matches for you, then have your count just sum the results of that column.
Solution image
So we put the values we want to find in some reference cells, the BASE match goes in G2, and the VALUE we're looking for goes in G3.
In column D we put a formula in D2:
"=IF(B2=$G$2,IF(ISERR(SEARCH($G$3,C2)),0,1),0)"
Returns 0 if the BASE matches and we can find at least one occurent of VALUE
B2=$G$2 - Does the BASE column match the BASE we're looking for
ISERR(SEARCH($G$3,C2)) - Does searching for the VALUE return an error (if it does, we know that VALUE isn't there)
Copy this formula to all the cells in column D, and then you can just use a simple SUM(D:D) to count the occurences where your conditions are met.
The neater but slightly more complex alternative is to use an array formula to do the match finding and counting all in one formula. This would look like this:
"{=SUM(IF(B:B=$G$2,IF(ISERR(SEARCH($G$3,C:C)),0,1)))}"
Pretty much the same as the formulas in column D, but now we use B:B and C:C in place of B2 / C2 etc. and stick the SUM around the whole thing. If you finish editing with Ctrl+Shift+Enter instead of just Enter, that'll make it an array formula.
Microsoft Array Formula Guidelines
NB: this WILL NOT count multiple occurences of 4 in a single VALUE cell.
p.s. Assuming you would want it to actually return 3 in this case (you missed the 4 in C7)

Resources