excel: looking up values using INDEX - excel

i am using the following formula to index my data on sheet 2 and find the matching values which are similar or exact to that which is typed into my cell K22 on sheet 1.
I have used the below code and combined it together using & statements to give me multiple results from seperate columns.
=IF(ISERROR(INDEX(Sheet2!$A$1:$D$10004,SMALL(IF(LEFT(Sheet2!$A$1:$D$10004,5)=LEFT(Sheet1!$K$22,5),ROW($A$1:$D$10004)),ROW(1:1)),1)),"",INDEX(Sheet2!$A$1:$D$10004,SMALL(IF(LEFT(Sheet2!$A$1:$D$10004,5)=LEFT(Sheet1!$K$22,5),ROW($A$1:$D$10004)),ROW(1:1)),1))
so my finished combined code looks like this:
=`IF(ISERROR(INDEX(Sheet2!$A$1:$D$10004,SMALL(IF(LEFT(Sheet2!$A$1:$D$10004,5)=LEFT(Sheet1!$K$22,5),ROW($A$1:$D$10004)),ROW(1:1)),1)),"",INDEX(Sheet2!$A$1:$D$10004,SMALL(IF(LEFT(Sheet2!$A$1:$D$10004,5)=LEFT(Sheet1!$K$22,5),ROW($A$1:$D$10004)),ROW(1:1)),1)) & " - " & IF(ISERROR(INDEX(Sheet2!$A$1:$D$10004,SMALL(IF(RIGHT(Sheet2!$A$1:$D$10004,5)=RIGHT(Sheet1!$K$22,5),ROW($A$1:$D$10004)),ROW(1:1)),3)),"",INDEX(Sheet2!$A$1:$D$10004,SMALL(IF(RIGHT(Sheet2!$A$1:$D$10004,5)=RIGHT(Sheet1!$K$22,5),ROW($A$1:$D$10004)),ROW(1:1)),3)) & " - " & IF(ISERROR(INDEX(Sheet2!$A$1:$D$10004,SMALL(IF(LEFT(Sheet2!$A$1:$D$10004,5)=LEFT(Sheet1!$K$22,5),ROW($A$1:$D$10004)),ROW(1:1)),4)),"",INDEX(Sheet2!$A$1:$D$10004,SMALL(IF(LEFT(Sheet2!$A$1:$D$10004,5)=LEFT(Sheet1!$K$22,5),ROW($A$1:$D$10004)),ROW(1:1)),4))
so when i perform a search this displays the results like so
Supplier x - Manchester - V0001
i am using ROW() function because i have many of these formulas in seperate rows on my sheet to return multiple search results.
i am also using LEFT() function as a way of telling it to find similar results rather than exact, because someone may type 'Hotel' instead of 'Hotels' etc.
my data on sheet 2 looks like this:
Name Description Location Number
Supplier X Catering Manchester v0001
Supplier Y Hotels London v0002
Supplier Z Catering London v0003
so if i do a search for catering in my cell K22 on sheet 1 i would get a result like this:
Supplier X - Manchester - V0001
Supplier Z - London - V0003
But now if i want to just search for catering suppliers in London, i get the same search results again:
Supplier X - London - V0001
Supplier Z - London - V0003
however it changes the location of supplier x from manchester to london, even though in my column data on sheet 2, supplier x location is manchester?
Can someone please show me why this is happening as it should only be returning the suppliers which have a matching location of London next to them.
Thanks in advance,

Related

Nested IF statements assistance

I made a small workbook that exactly mimics the original formulas I posted. The purpose of the workbook is to calculate the bonuses for each employee based on various inputted combinations (listed below). Here is how my workbook is laid out:
Data Tab
Bonus Tab
Base Bonus Tab
Summary Tab
Picture of the Data tab that I utilize to input the different combinations:
Data Tab
List of the combinations:
Employee % (cell B3) & Company % (cell B4) cells have numbers inputted = Combo 1 (range: 0%-100%)
Employee $ (cell B5) & Company $ (cell B6) cells have numbers inputted =Combo 2 (range: $0-no limit)
Base Salary (B2) is Yes & Employee % (cell B3) cells have been inputted = Combo 3 (Base Salary is either Yes or blank)
Base Salary (B2) is Yes & Job Title (A8) & Employee % (cell B8) cell have been inputted = Combo 5
I use cell C1 for an IF statement to dictate which formula to use based on the combinations above. (ex. numbers in B5 & B6 = 1)
=IF(AND($B$2<>"",$A$8<>"",$B$8<>""),5,IF(AND($B$2<>"",$B$3<>""),3,IF($B$3<>"",1,IF($B$5<>"",2))))
Picture of the Bonus Tab: Bonus Tab
Picture of the Base Bonus Tab: Base Bonus Tab
Picture of the Summary Tab: Summary Tab
I have created formulas for each combinations separately, but as soon as I try to combine them into one, I get the Too many arguments error message since combo 3 & combo 5 use false within the IF statement. I am attempting to avoid making a calculations table and would prefer utilizing one formula on the summary tab by employee in column B.
I will further explain combo 3 specifically - If the base bonus is less than the regular bonus, than multiply the base bonus * Employee % + Company&Vendor bonus * Company %. If base bonus is more than regular bonus, than multiply regular bonus * Employee % + Company&Vendor bonus * Company %.
Example:
Bobby
Base Bonus $50 < Regular Bonus $100
$50 * 50% employee % = $25
+ $200 company + $0 vendor * 50% company = $100
Final answer is $125 if base bonus if < regular bonus
I will further explain combo 5 specifically - If the base bonus is less than the regular bonus, than multiply the base bonus * employees job title Employee % + Company&Vendor bonus * job title Company %. If base bonus is more than regular bonus, than multiply regular bonus * employees job title Employee % + Company&Vendor bonus * job title Company %.
Example:
Bobby
Base Bonus $50 < Regular Bonus $100
Find Bobby's Job title to determine Employee % & Company %
75% Employee % for Officers and 50% Company %
75% * $50 + 50% * ($200 Company & $0 Vendor) = $137.5
Final answer is $137.5 of base bonus if < regular bonus
Here is list of each formula by combo:
Combo 1:
=IF(Data!$C$1=1,Data!$B$3*Bonus!D2+Data!$B$4*(Bonus!E2+Bonus!F2))
Combo 2:
=IF(Data!$C$1=2,IF(SUM(Bonus!B2:C2)<1,0,1)*Data!$B$6+Data!B5))
Combo 3:
=IF(Data!$C$1=3,IF(VLOOKUP(Summary!A2,'Base Bonus'!$A$2:$B$5,2,FALSE)<VLOOKUP(Summary!A2,Bonus!$A$2:$D$5,4,FALSE),VLOOKUP(Summary!A2,'Base Bonus'!$A$2:$B$5,2,FALSE)*Data!$B$3+Data!$B$4*(Bonus!E2+Bonus!F2),VLOOKUP(A2,Bonus!$A$2:$D$5,4,FALSE)*Data!$B$3+Data!$B$4*(Bonus!E2+Bonus!F2)))
Combo 5:
IF(Data!$C$1=5,IF(VLOOKUP(Summary!A2,'Base Bonus'!$A$2:$B$5,2,FALSE)<VLOOKUP(Summary!A2,Bonus!$A$2:$D$5,4,FALSE),VLOOKUP(Summary!A2,'Base Bonus'!$A$2:$B$5,2,FALSE)*VLOOKUP(VLOOKUP(Summary!A2,Data!$A$16:$B$19,2,FALSE),Data!$A$8:$C$11,2,FALSE)+(Bonus!E2+Bonus!E2)*VLOOKUP(VLOOKUP(Summary!A2,Data!$A$16:$B$19,2,FALSE),Data!$A$8:$C$11,3,FALSE),VLOOKUP(A2,Bonus!$A$2:$D$5,4,FALSE)*VLOOKUP(VLOOKUP(Summary!A2,Data!$A$16:$B$19,2,FALSE),Data!$A$8:$C$11,2,FALSE)+(Bonus!E2+Bonus!E2)*VLOOKUP(VLOOKUP(Summary!A2,Data!$A$16:$B$19,2,FALSE),Data!$A$8:$C$11,3,FALSE)))
Hopefully this is a lot more clear than my initial post and can easily be replicated. Let me know if you have any questions, Thank you!
I found some issues in your formulas
Combo3 In the else option you have A2 following the pattern it should be Summary!A2
Combo5 the sum is in the same cell you have (Bonus!E2+Bonus!E2) it should be (Bonus!E2+Bonus!F2)
I didn't record the initial nested If to compare why it is not working. I got this:
Final Nested:
=IF(Data!$C$1=1,Data!$B$3*Bonus!D2+Data!$B$4*(Bonus!E2+Bonus!F2),IF(Data!$C$1=2,IF(SUM(Bonus!B2:C2)<1,0,1)*Data!$B$6+Data!B5,IF(Data!$C$1=3,IF(VLOOKUP(Summary!A2,'Base Bonus'!$A$2:$B$5,2,FALSE)<VLOOKUP(Summary!A2,Bonus!$A$2:$D$5,4,FALSE),VLOOKUP(Summary!A2,'Base Bonus'!$A$2:$B$5,2,FALSE)*Data!$B$3+Data!$B$4*(Bonus!E2+Bonus!F2),VLOOKUP(Summary!A2,Bonus!$A$2:$D$5,4,FALSE)*Data!$B$3+Data!$B$4*(Bonus!E2+Bonus!F2)),IF(VLOOKUP(Summary!A2,'Base Bonus'!$A$2:$B$5,2,FALSE)<VLOOKUP(Summary!A2,Bonus!$A$2:$D$5,4,FALSE),VLOOKUP(Summary!A2,'Base Bonus'!$A$2:$B$5,2,FALSE)*VLOOKUP(VLOOKUP(Summary!A2,Data!$A$16:$B$19,2,FALSE),Data!$A$8:$C$11,2,FALSE)+(Bonus!E2+Bonus!F2)*VLOOKUP(VLOOKUP(Summary!A2,Data!$A$16:$B$19,2,FALSE),Data!$A$8:$C$11,3,FALSE),VLOOKUP(B2,Bonus!$A$2:$D$5,4,FALSE)*VLOOKUP(VLOOKUP(Summary!A2,Data!$A$16:$B$19,2,FALSE),Data!$A$8:$C$11,2,FALSE)+(Bonus!E2+Bonus!F2)*VLOOKUP(VLOOKUP(Summary!A2,Data!$A$16:$B$19,2,FALSE),Data!$A$8:$C$11,3,FALSE)))))

Excel Commission Formula

Wondering if I could get help getting the correct formula to figure out the comm% based off the price it was sold at.
Basically, there are two spreadsheets.
First one is our price grid to show what the commission pct will be:
Product - 20% - 15% - 10%
Widget 1 - 3990 - 3490 - 3090
Widget 2 - 4990 - 4490 - 4090
Widget 3 - 5990 - 5490 - 5090
The second spreadsheet would list the Products sold and at what price it was sold at:
Widget 2 - $4690
Widget 3 - $5100
Widget 1 - $4000
I was thinking INDEX/MATCH. I can do the MATCH correctly to find the correct row, but I'm not sure how to incorporate that price range lookup into the formula.
In the example I gave above the commission should be 15%, 10% & 20% respectively.
Need to create a formula that matches the Product and then takes the price sold at and matches it to what column it would fall under and give me the % for that column.
I've spent weeks search the net and I can only get half way there. The MATCH to figure out which row the Product is on is simple, it's the price matching that's got me stumped.
Thanks.
You can solve this by making use of the rarely used Hlookup function, using it's range_lookup option. The only requirement for it is that you reorder your commission data from low% to high%. like this:
Product 10% 15% 20%
Widget 1 3090 3490 3990
Widget 2 4090 4490 4990
Widget 3 5090 5490 5990
If you've done this, you can use this formula to get the correct commission
=OFFSET(Sheet1!$A$1;0;MATCH(HLOOKUP(INT(SUBSTITUTE(B1; "$"; ""));INDIRECT("Sheet1!"&MATCH(A1;Sheet1!$A:$A ) & ":" & MATCH(A1;Sheet1!$A:$A ));1; TRUE);INDIRECT("Sheet1!"&MATCH(A1;Sheet1!$A:$A ) & ":" & MATCH(A1;Sheet1!$A:$A)) )-1)
This is the breakdown:
Format input as integer (commission data is int, values are $)
SUBSTITUTE(B1; "$"; "")
Use the input to put together the reference row for the Hlookup. We use indirect to add the sheetname and ":" to the reference.
INDIRECT("Sheet1!"&MATCH(A1;Sheet1!$A:$A ) & ":" & MATCH(A1;Sheet1!$A:$A ))
Use Hlookup to find the matching value:
HLOOKUP(INT(SUBSTITUTE(B1; "$"; ""));INDIRECT("Sheet1!"&MATCH(A1;Sheet1!$A:$A ) & ":" & MATCH(A1;Sheet1!$A:$A ));1; TRUE)
Use the found value in a horizontal match function to find the used column, and substract 1:
MATCH(<hlookup>; INDIRECT("Sheet1!"&MATCH(A1;Sheet1!$A:$A ) & ":" & MATCH(A1;Sheet1!$A:$A))) - 1
Use Offset to find the matching value
Offset(Sheet1!$A$1;0; <match>)

LOOKUP function in Excel to search values on left and right

The scenario I'm facing is that in my company we have mixed naming conventions for servers and workstations like:
COUNTRYCODE-WORKSTATION1
WORKSTATION10-COUNTRYCODE
COUNTRY-SERVER1
SERVER1-COUNTRYCODE
So sometimes I may find names like: BR-WK1 or SRV42-US.
I need to create a PivotTable to extract the amount of events per country so I need to come up with a Lookup function that looks at the first two characters in a cell and if it finds a country code it returns the country code in a country column for that row. If it does not find a country code, it looks at the first two characters on the right, and so on. Country code list will be available in another sheet.
IF(LEFT(CELL,CHARNUMBER){COUNTRY LIST}) then (CELLCOUNTRY == {MATCH COUNTY}))
ELSE(RIGHT(CELL,CHARNUMBER){COUNTRY LIST} then (CELLCOUNTRY == {MATCH COUNTRY}))
Excel:
COUNTRY MACHINE NAME EVENT DATE TIME
BR BR-WK1 Critical type 1 08/01/2015 01:15
US SRV42-US Critical type 2 08/01/2015 01:15
BR WK100-BR Warning type 8 08/01/2015 01:15
US US-SRV420 Critical type 1 08/01/2015 01:15
Pivot table:
Row Labels Count of EVENT
BR 2
US 2
Grand Total 4

How to count unique names (First Name Col A and Last Name Col B) with additional criteria in other columns

Sheet 1 contains data entry from a user form. See data below.
A B D I
First Name Last Name Date Type
Jane Doe 1/15/15 Fall
Jane Doe 1/24/15 Behavior
Jane Doe 2/21/15 Fall
Angel Wings 1/10/15 Fall
Sheet 2 calculates the data from sheet 1 and tracks and trends the information
Count the number of unique names based on First and Last Name. I figured out the Array formula for this one which is:
=SUM(IF(FREQUENCY(IF('Event Tracker'!A5:A1502&'Event
Tracker'!B5:B1502<>"",MATCH('Event Tracker'!A5:A1502&"#"&'Event
Tracker'!B5:B1502,'Event Tracker'!A5:A1502&"#"&'Event
Tracker'!B5:B1502,0)),ROW('Event Tracker'!A5:A1502)-ROW(A5)+1)>0,1))
Here is where I really need help - I have tried every variation I can think of.
2.Count the number of unique patients (Col. A + Col B) with an event occurring between a specified date based on date in col. D (>=1/1/15 and <=1/31/15)?
How many unique patient names (Col A + Col B) had a Fall (Col I)?
How many unique patient names (Col A + Col B) had a Fall (Col I) between >=1/1/15 and <=1/31/15 based on the date in column D?
You can add additional conditions at the start of the FREQUENCY function, e.g. for how many different patients had a fall, use this:
=SUM(IF(FREQUENCY(IF('Event Tracker'!I5:I1502="Fall",IF('Event Tracker'!A5:A1502&'Event Tracker'!B5:B1502<>"",MATCH('Event Tracker'!A5:A1502&"#"&'Event Tracker'!B5:B1502,'Event Tracker'!A5:A1502&"#"&'Event Tracker'!B5:B1502,0))),ROW('Event Tracker'!A5:A1502)-ROW(A5)+1)>0,1))
To add extra conditions you can just keep adding IFs in the same place......but don't forget to add the appropriate parentheses.
For between two dates the syntax is as follows:
=SUM(IF(FREQUENCY(IF('Event Tracker'!D5:D1502>="1/1/15"+0,IF('Event Tracker'!D5:D1502<="1/31/15"+0,IF('Event Tracker'!A5:A1502&'Event Tracker'!B5:B1502<>"",MATCH('Event Tracker'!A5:A1502&"#"&'Event Tracker'!B5:B1502,'Event Tracker'!A5:A1502&"#"&'Event Tracker'!B5:B1502,0)))),ROW('Event Tracker'!A5:A1502)-ROW(A5)+1)>0,1))

Spreadsheet - ordering a column twice, using different scores (from 2 other colums)

I am working on a spreadsheet - currently google docs but happy to see answers relating to other spreadsheet software.
I have a list of foods (column A - Food)
I have list1 of "scores" (column B - Score1)
I have list2 of "scores" (column C - Score2)
I would like to add two new columns, ideally ordering the food from column A according to the scores, both list1 and list2 - so one new column ordering the foods based on the score1 from column B, and the other new columns based on the score2 from column C.
An example usually helps, so here is what I have:
Food Score1 Score2
a 12 45
b 96 67
c 100 32
Now, this would be "Version 1", on the way to getting what I would like:
Food Score1 Score2 Order1 Order2
a 12 45 3 2
b 96 67 2 1
c 100 32 1 3
Or, even better, "Version 2" - use the food name in the new columns, in the right order according to scores:
Food Score1 Score2 FoodScore1 FoodScore2
a 12 45 c b
b 96 67 b a
c 100 32 a c
I suspect that getting "Version 1" is probably achievable (but don't know how to do it)
I suspect that getting "Version 2" is not possible without some sort of procedural programming?
Hope someone can help!
Cheers
Or, even better, "Version 2" - use the food name in the new columns, in the right order according to scores:
Let A2:A10 - is your food range, B2:B10 - score1 range, D2:D10 - destination range ( FoodScore1 in your example)
Works both in EXCEL and in GOOGLE-SPREADSHEETS:
=INDEX($A$2:$A$10,MATCH(LARGE($B$2:$B$10,1+ROW(A2)-ROW($A$2)),$B$2:$B$10,0))
enter this formula in D2 and drag it down
If formula will give you an error, try to change , to ; (depends on your local settings).
P.s. for score2 formula would be the same, just change ranges from score1 to score2 (i.e. $B$2:$B$10 to $C$2:$C$10)
I would start by adding a rank column, with number 1 for the highest score, number 2 for the second highest, etc.
In Microsoft Excel, assuming that the first column is A and that all the scores are unique, you could simply have a formula like
=COUNT.IF(B:B, ">=" & $B1)
in column D1, and similarly in column E for the second score.
Then if you fill column F with the ranks 1, 2, 3, ... you can simply do a VLOOKUP. Or, in this case, an equivalent solution with INDEX and MATCH - because you want to lookup the rank in column F and return the corresponding value from column A.
As you are working in a Google Spreadsheet, one would expect to see some Googliness in the solutions provided. Use this very simple, only usable in Google Spreadsheet, formula.
Formula
// FoodScore1
=QUERY(B2:D4, "SELECT B ORDER BY C DESC")
// FoodScore2
=QUERY(B2:D4, "SELECT B ORDER BY D DESC")
Screenshot
Explained
The data range of the QUERY function is simply B2:D4. Then a quasi SELECT statement is made to select only column B and ordered by column C or D, descendingly.
Reference
https://developers.google.com/chart/interactive/docs/querylanguage

Resources