Excel VLOOKUP or INDEX MATCH - excel

Lets say I have 3 columns of data
AMOUNT(A) AMOUNT(B) INVOICE(C)
55 49 4541
47 47 1515
42 47 4478
86 12 9993
12 100 1224
5 44 1452
100 4287
99 4444
What I need to check to see if the value in column A matches a value in column B. If there is a match, it will return the value from column C in column D. Now this is easy with a VLOOKUP however I am dealing with 700+ lines and there are multiple amounts that match. INDEX(MATCH) could work but it only returns one value. Is this a VB only problem?
I.E Value 47 exists in column B twice so therefore column D would return both invoice numbers (1515 - 4478)

In VBA, the problem would be trivial as you have already correctly described the logic with the problem statement itself.
Using Excel functionality only, without VBA is the interesting problem. You need to do the following steps to achieve an output that looks like this...
The steps are as follows:
Pivot Table: Make a pivot-table from the Columns (B) and (C) with Rows Fields as (B) and (C) and the minimum of AMOUNT(B) as the Value field. (See Figure below)
Helper Columns: Make a column on the side of the pivot table, say (Q) which is simply equal to everything in column (P)
Contd ... : In column (R) (which unfortunately happens to be in the sheet's column Q, sorry for the confusion there), as shown, for cell Q20 for e.g. put in the formula
=IF(P21=P20,Q21&","&M20,M20)
That will result in the creation of something like the table below:
Table:
(P) (Q)
12 9993
44 1452
47 4478,1515
47 4478
49 4541
99 4444
100 4287,1224
100 4287
Now the hard work is done. All you need to do is to lookup using VLOOKUP key-value pairs from this helper table (P)(Q)
- It will be very fast because the pivot table always keeps it sorted and hence an exact LOOKUP is not necessary.
- Screenshots are shown below for the Pivot table as well as for the final VLOOKUP formula
Pivot Table and Helper Table:
Final Formula:

so I'm using the Countif to see if there are dups based on column A.
In the D column type, =IF(COUNTIF($A$2:$A$9,B2)>0,C2,"")

Related

Conditional Formatting in Pivot Table in Excel based on text field

I would like to color code a pivot table based on a text field within the data.
This is a mock up, as I'm at a loss as to how this can be done. One of the tricky parts is that you can't actually display the text field that is the basis for the color.
Thank you,
Neil
Contract
Month
PayStatus
Payment
1
Jan-21
Complete
90
2
Jan-21
Complete
95
3
Jan-21
Complete
93
4
Jan-21
Complete
94
1
Feb-21
Pending
91
2
Feb-21
Complete
95
3
Feb-21
Complete
92
4
Feb-21
Complete
94
2
Mar-21
Complete
96
3
Mar-21
Pending
93
4
Mar-21
Pending
94
2
Apr-21
Complete
95
3
Apr-21
Pending
94
Mock-up Pivot Mock-up (color coded)
You still don't need to use VBA to get the results you're looking for, but there is a little work to do in order to set it up. The solution is to use Conditional Formatting in which the formula is VLOOKUP. To make it work, you need to modify your table slightly.
VLOOKUP works by finding a unique value in the first column of a table or range. The first column values in your table are not unique, nor are the values in the second column. But if you combine the first and second columns, you can create a unique value. A column must be added to the left of your data to create this unique value:
The formula in Column A combines the values in columns B and C:
=B2&"+"&TEXT(C2,"mmm")
(There's a reason to format the date as just the Month, more later)
What we're ultimately looking for in your formatting rules is when any value in the pivot table, for a given month and contract, matches either "Complete" or "Pending". Because we've set up the data with the helper column, we can now create a `VLOOKUP' that can work for us. So we need a formula that does this:
VLOOKUP(unique value based on month and contract,get the pay status) = "Complete"
VLOOKUP(unique value based on month and contract,get the pay status) = "Pending"
The formula in the VLOOKUP has to reference back to the source data (when it's inside the pivot table). In order to lookup that unique value, we have to create it by combining values from the pivot table. If the VLOOKUP formula was in Cell B6 in the pivot table:
Then the formula will be:
=VLOOKUP($A6&"+"&B$4,Sheet1!$A$1:$E$14,4,FALSE)="Complete"
Notice how the "lookup value" is not a single cell, but we're creating the same unique string/value in the helper column.
In your pivot table, click in the values area ("Sum of Payment") in Cell B6, then select Home -->Conditional Formatting-->Manage Rules. Next "Add New Rule" and then make sure your rule looks like this:
Create a second rule in the same manner and apply it to the pivot table.

unique value based in a different columns data

Okay so here’s what I need…. And let me preface this by saying I know this can be done in a pivot table however, I am trying to avoid using a pivot table.
Col J Col M Col Q
origdest weeknum Wks Shipped - Prior 12 Months
AAABBBCCC 48 3
XXXX 44 2
AAABBBCCC 48 3
XXXX 44 2
AAABBBCCC 44 3
XXXX 45 2
YYYY 48 1
AAABBBCCC 3 3
ZZZZZ 48 1
In column Q, I need a formula that will give me the unique value in column M of the matching column J (which should give me the result shown in column Q.. In other words, I need to know how many weeks that “origdest” shipped. It seems like it should be pretty simple but I can’t seem to make anything work and I have had an issue with entering an array formula, it hangs up my computer.
There is a fairly standard method of achieving unique counts involving the SUMPRODUCT function and the COUNTIF function. Your situation demands that more criteria be introduced by substituting COUNTIF for the COUNTIFS function.
In Q2 try this standard formula.
=SUMPRODUCT(((J$2:J$99=J2)*(J$2:J$99<>""))/COUNTIFS(J$2:J$99, J$2:J$99&"", M$2:M$99, M$2:M$99&""))
Fill down as necessary. Your results should resemble the following.
      

Excel Function to sum values from table based on a comma separated list

I am trying to find a function that will look at a table and sum all the values where the string appears in my comma separated list. I can get sumproduct to work if my list is separated into different cells, but I need the list to be in one cell. Here is what I'm looking for:
List in Cell A1: 2000,2100,2300
Table: A10:B16
A B
2000 20
2100 25
2200 32
2300 65
2400 72
2500 12
2600 2
I'm looking for a result of: 110
Any help would be appreciated.
Thanks!
I am assuming that you can use another column but not for your list?
If so you can use the formula below in column C
=IF(ISERROR(FIND(A2,$A$1,1))=FALSE,TRUE,FALSE) with A2 being the 1st cell in which the data is contained.
This is searching through your comma separated list and evaluating against the data in column B whether it exists in the list, if so then returns true if not false.
Now you can use the SUMIF function to return those matching true in your new column C.
=SUMIF(C2:C8,TRUE,B2:B8)
If having the evaluation column C is a problem for other users you could always hide it

How to get unique values in a column using excel formula

I have Excel Data like below
JID Val
1001 22
1030 6
1031 14
1041 8
1001 3
2344 8
1030 8
2344 6
1041 8
How do i get the unique JID values like below using formula?
UJID
1001
1030
1031
1041
2344
Here is a solution to get a list of unique items from your tables
There is two parts to this solution.
Part 1) Unique Count
{=SUM(IF(FREQUENCY(IF($A$2:$A$10<>"",MATCH($A$2:$A$10,$A$2:$A$10,0)),ROW($A$2:$A$10)-ROW($A$2)+1),1))}
This will count the number of unique items in your data table and will ignore any blanks
*Note this is an array formula and you will need to use "Ctrl" + "Shift" + "Enter" to use
Part 2) Unique List
This formula will give you the list of unique items in your table
={IF(ROWS($E$5:E5)>$E$2,"",INDEX($A$2:$A$10,SMALL(IF(FREQUENCY(IF($A$2:$A$10<>"",MATCH($A$2:$A$10,$A$2:$A$10,0)),ROW($A$2:$A$10)-ROW($A$2)+1),ROW($A$2:$A$10)-ROW($A$2)+1),ROWS($E$5:E5))))}
again this is an array formula. You can then drag this formula down to get all the unique items.
This formula is a dynamic formula, meaning you can set the data range past your current data range and the list will update as you enter new values.
*Here is a great video to watch to understand this further
https://www.youtube.com/watch?v=3u8VHTvSNE4
You can use the remove duplicate function
Select the column range
Go to Data Tab
then click on Remove Duplicates
I think I've found a more elegant workaround without array-functions or built-in functions:
1st column (ID):
this is the array from we'd like to select distinct values
2nd column (criteria):
checks whether this is the first occurrence
=IF((ROW()-1)=MATCH(A2,$A$2:$A$500,0),1,0)
3rd column (cumulative):
=SUM($B$2:B2)
4th column (count):
this is constant 1
5th column (unique ID):
=OFFSET($A$2,MATCH(ROW()-1,$C$2:$C$501,0)-1,)
6th column (count):
=SUMIF(A2:A21,F2,D2:D21)

Find all values greater or equal than a certain value

Let's say I have the following table.
Team Score
AA 81
BB 67
CC 44
DD 1.5
JJ 279
LL 49
TT 201
GG 158
MM 32
HH 89
I want to get all teams that scored more than 80 in another table. I tried the Index + Match function as follows but it only gives me the smallest value greater than 80.
Here is the code:
=INDEX($A$2:$A$11,MATCH(80,$B$2:$B$11,-1))
Although I put the values in the lookup_array argument in descending order, this function only gives me one answer: The smallest value greater than 80.
I am trying to do this without having to sort the array and with a huge database mind you. Thank you.
Enter this formula to D2 and press CTRL+SHIFT+ENTER to make it an array formula, then drag it down.
=INDEX($A$1:$A$11,SMALL(IF($B$2:$B$11>=80,ROW($B$2:$B$11)),ROW(1:1)))
See How to look up a value in a list and return multiple corresponding values for details.
How about using an AutoFilter? You're then quite flexible in filtering for values in column score.
If you don't want to use vba, in a third column you could have
=if(B2 > 80, A2, "")
and copy that formula down. You could even put this column of formulas in another tab and either delete the rows that have nothing in them manually or write code that will do that for you.
Create a PivotTable (Team for ROWS, Score for Sigma VALUES, then filter the Sum of Score column for Number Filters, Greater Than..., and 80 next to Show rows where: is greater than *, OK.
* or perhaps is greater than or equal to.

Resources