How can I assign a value to a cell by referencing a seperate table in Excel/Mac Numbers? - excel-formula

Table 2
Pts
# of tix sold
0
100
1
200
2
300
3
400
4
500
5
600
Example: In Table 1 Tim sold 198 tickets. He didn't make it to 200 tickets sold, so he gets 0 pts. Bill sold 220, so he gets 1 pt. The points show in the cell next to the name on Table 1, but references table 2.
I tried using xlookup and index, but I don't really know what I'm doing.

XLOOKUP provides several matching modes, and one is "exact match or next smallest" which is what you want. If the lookup value is 225, I want it to start down the list, and if it finds 225, it selects that row; if it encounters any number > 225 then it knows it's gone too far and selects the previous number. This sounds like the logic you want.
Assume:
Tim's ticket count is in B2, and you want his points in C2;
The lookup table is on a second worksheet, titled "Table2";
The lookup table headers are A1:B1, and the data is the 6 rows below that;
The lookup table should be in ascending ticket count order.
Then, in table1 cell C2 place this:
=XLOOKUP(A2, table2!$B$2:$B$7, table2!$A$2:$A$7, "", -1)
And copy it down the rows of column C.
The -1 argument tells lookup "exact match or next smallest".

Related

How to get maximum number and name from 2 columns? (Excel)

I have this (example):
Luffy 320
Coby 350
Zoro 180
Now I want to show the max from this info, with number and text (in seperate cells) like this:
col 1 col 2 col 3
1st 350 Coby
2nd 320 Luffy
3rd 180 Zoro
The 2nd Column no problem with the MAX() formula.
For the 3rd column to get the text I've tried the MAX(...) and INDEX(...) formulas but nothings working ...
Can anyone help me?
You first need to get which value is the largest, second largest and so on.
You can use the function LARGE(range, n) for this.
So in your col 2 use this formula:
=LARGE(B:B,1)
=LARGE(B:B,2)
=LARGE(B:B,3)
Assuming B is the column with the values.
Then we need to match this value and get the name
=INDEX(A:A,MATCH("the above calculated cell",B:B,0))
With the above calculated cell I mean the LARGE function cell. And assuming column A is the column with the names.
This should give you a dynamic table that will update when values or names change.
I'm not sure how you manage to get that column 2 using MAX formula since it only outputs the largest number of the inputs and thus can't output 2nd and 3rd position.

EXCEL: Take the average of a column in row (n-5,n-1) if row n fulfills a condition

There are 50 rows. The first column (A), each row has has a ID number. They are not sorted in any way and should not be either and there are no duplicated ID numbers. When the ID is 0 then consider 4 rows before that row, take the mean value of those values in clumn C between those 4 rows. If it helps It is always the last row that has value ID = 0.
What I have done so far is that I can find the ROW number of the ID = 0 using the following formula:
ROW(INDEX(A3:A53,MATCH(TRUE,INDEX(A3:A53=0,),0)))
Now I don't know how to navigate 4 rows upwards and take the corrosponding values in Column C.
If you use an extra column (say column Z), then paste this code into that column starting on row 4 (NB it won't work properly for the first 3 rows because there are not 4 above to check).
=IF($A4 =0, AVERAGE($C1:$C4), "Not Relevant")
so put that code in Z4, then press ctrl+E to flash fill it downwards.
Hopefully, on each line where the ID is 0, there will be an average of that line and the previous 3 in column Z on that row.
Use:
=AVERAGE(INDEX(A3:A53,MATCH(TRUE,INDEX(A3:A53=0,),0)-5):INDEX(A3:A53,MATCH(TRUE,INDEX(A3:A53=0,),0)-1))

How to use a VLOOKUP as a criteria in SUMIF?

First allow me to provide some background:
I have two tables, the first with one column that has a key value, which is just one letter of the alphabet and a second column with values that later I want to sum. The second table also has two columns. The first contains a list of the distinct values from the key column of the first table, and the second contains a binary value of 1 or 0. Examples below:
Table 1: Table 2:
A 50 A 1
A 50 B 0
B 100 C 0
C 125
The binary values in Table 2 are variable based on other information contained in my workbook. Now what I want to do is to sum all of the values in Table 1, where the Primary key is "turned on" in Table 2, aka the value in the second column is 1. I've tried multiple iterations of using SUMIF and VLOOKUP and LOOKUP as the criteria but can't get anything to work. Can anyone help out with a way, either using VBA or in the cell formula itself, to get this done?
Thanks in advance.
How's this? Place this next to the 1 or 0 in your Table2, =IF(F1>0,SUMIFS($B$1:$B$4,$A$1:$A$4,E1),""):
and if you drag that down, it'll return blanks for the "letter" that doesn't have duplicates.
Edit: Or, per #pnuts, this =SUMIF(A:A,"="&INDEX(E:E,MATCH(1,F:F,0)),B:B)

Issues with VLOOKUP in Excel

I have a tax table in one sheet that has a list of tax values. For example:
Sheet1: Tax Tables
A B C
1 Min Max Taxed
-------------------
2 50 100 10
3 100 200 20
4 200 300 30
In another sheet I have a gross income value of say 120 in cell A1. What I want to do is have a vlookup (I'm assuming that's what I should use) that checks cell A1 to see if it's between the Min and Max and then outputs the taxed amount in B1.
Sheet2: Income
A B
1 Gross FedTax
-----------
2 120 Value from Column C goes here
I already have the sheet in Tax Tables set up with named spaces A:C=Min and B:C=Max
I tried doing this:
=AND(VLOOKUP(<A1,Min,3,False),VLOOKUP(>A1,Max,2,FALSE))
But not even close...
I just want to check column A in the first sheet to see if it's less than the the value in the second sheet, and check column B in the first sheet against the value in the second for if its more, then put the value in column C in the first sheet into the cell next to the value in the second sheet.
To use a VLOOKUP, put your maximums and minimums in the same column.
Then use the TRUE argument, which means it looks for the next value that matches. Assuming the value you're looking up in D2, you'd put a formula like this in E2:
=VLOOKUP(D2,$A$2:$B$5,2,TRUE)
First of all it is unclear what you would apply when the amount is exactly 50/100/200/300/... So i decided to include the lower limit in the interval and exclude the upper limit.
For this problem I would use a sumifs like this (you have to decide on which side to put the equal sign:
=SUMIFS(Sheet1!C:C;Sheet1!A:A;"<="&A1;Sheet1!B:B;">"&A1)
This would only take those elements in column C that have a value in column A smaller than or equal to 120 and a value in column B greater than 120

Finding matching value in sheet 2 and copy adjacent cells value in sheet 1

I have searched through many similar topics but could find nothing that will do what I need.
I am trying to create a worksheet that will track scores for a darts game.
On Sheet 1 I have two columns that simply tracks each players throws from 501 down to 0
Row 25 is the amount remaining for each player.
In Sheet 2 I have 2 columns. The Column A contains scores that you can check out on, and Column B contains the checkout e.g. (T20, T20, D18). So if the value in row 25 of Sheet 1 matches any of the values in Column A of sheet 2, the I want to display the Value of Column B in the matching row on Sheet 2 Underneath the remaining score on Sheet 1.
Can anyone point me in the right direction?
not sure what you mean exactly, but this formula in row 26 should do the trick:
=index('Sheet 2'!$B:$B;match(A25;'Sheet 2'!$A:$A;0))
if your list separator is comma ,, use that instead of semicolon ;
you might want to use 1 as the third argument of match function, if you want to display the checkout according to the nearest match that is bigger than the number in row 25 and the column A in Sheet 2 is sorted in ascending order (1-9)
or -1 if you want the nearest match that is smaller and column A is sorted in descending order (9-1)
You can use this:
=IFERROR(VLOOKUP(A4, Sheet2!$C$2:$E$65535, 3, FALSE),0)

Resources