I want to create a cell which returns the column of a table. The column number should depend on a different variable. How would I do this?
For example,
Cell X
Column A
Column B
Cell 1
Cell 2
Y = random variable or cell
Cell X should return the Cell 2 if Y=2 and return Cell 1 if Y=1
I have tried a lot of research but all of them show finding a value from matching or looking up.
Use the INDEX() Function.
In this answer I'm assuming the fixed row number is row 1 (not including the headers row), and that what you describe as
Y = Random variable or cell
is the value of cell Y1
=INDEX(Table_Name, 1, Y1)
Related
I would like to calculculate the value of column X at the following table.
The logic is the followings.
the value of X = its id itself if the value of A is the first value.
the value of X = the id of first A if the value of A is not the first one.
this is the example of the data and the expected results are already filled in column X (Yellow cells).
there are no data in column X at actual data.
Formula is:
=INDEX(A:A, MATCH($B1,B:B,0), 1)
Where:
A:A - a range is column A
B:B - a range is column B
$B1 prevents shift B column but not row
INDEX gets value from a range by a row and col(1)
MATCH finds value in range and returns a row
If I have rows 1:m populated with values in column A, and in column B I have rows 1:n populated with values, where n < m. How can I find the sum of values in column A from row 1 up to row n.
In other words, how can I sum the values in Column A down to the last row of data in Column B where both Columns may have more values added to new rows at any time.
UPDATE: To ignore text values
=SUMPRODUCT(IFERROR((ROW(A:A)<=MAX(IF(B:B<>"",ROW(B:B))))*A:A,0))
This will produce a 0 value when an error occurs so the formula behaves for values only.
Original Answer:
In addition to the other answer -
If you are looking for total of A where B has a value then:
=SUMIF(B:B,"<>",A:A)
This is pretty self explanitory, =SUMIF(range,criteria,[sum_range]) we check B:B for non blanks and then sum the corresponding cells from A:A.
If you are looking for total of A1:An where n is the last row with a value from column B then:
This will need to be entered as an array formula (when in the formula bar hit Ctrl+Shift+Enter)
=SUMPRODUCT((ROW(A:A)<=MAX(IF(B:B<>"",ROW(B:B))))*A:A)
Array formula's break down ranges and caluclate them them one cell (or row) at a time. The MAX rows is broken down as an array, the IF sormula is returning 0 for false (default) and the row number for true so MAX is then grabbing the highest row number from the array (18 in the below example).
The Sumproduct formula is then producing true/false (1 or 0) for each cell in A:A where the row is less than or equal to the MAX row of non blank entries in B:B.
The formula then multiplies the true/false results (0 or 1) by the value in the corresponding A:A cell thus when the condition is met we have 1 x the value being summed and when the condition is not met then 0 will be summed (0 x the value).
I hope this helps explain the logic, feel free to probe my brain for more of an explanation if not.
The following formula dynamically determines the row of the last entry in column B and sums the values in column A up to this row.
=SUM(A1:INDIRECT("A"&COUNTA(B:B)))
I have a table drawn in excel that indicates a cell value determined by specific range of 5 values each on the x and y axis.
I have a group of three columns, and for each row, I want to enter a value in one cell (x value) and another value in another cell (y value) and populate a third cell with the xy value determined in the table.
How do I write an =IF( formula to execute this?
So, in very basic terms....x values for example (a, b, c, d, e) and y values (1, 2, 3, 4, 5), so the result cell would indicate if x = a and y = 3, result cell = a3?
Any help would be appreciated
If you have x values in column A starting at A1, Y values in col B starting at B1, in C1 you enter =A1&B1 and copy the formula down as required.
Apologies if this is already posted somewhere, I've been searching and still having issues.
In one Excel sheet I have a list of numbers in column A, call it "Sheet1". In another sheet (call it "Sheet2") I have 3 columns, which is essentially a list of number ranges. Column A is a beginning range, Column B is an ending range, and Column C is some non-numerical categorization and is the value I want to bring back. I would also like the range to be inclusive.
Example:
Sheet 1 cell A1 = 78335; Sheet 1 cell A2 = 80000; Sheet 1 cell A3 = 90000
(a) Sheet 2 cell A1 = 78334, Sheet 2 cell B1 = 78335; Sheet 2 cell C1 = "Design"
(b) Sheet 2 cell A2 = 79999, Sheet 2 cell B2 = 80001; Sheet 2 cell C2 = "Art"
(c) Sheet 2 cell A3 = 90001, sheet 2 cell B3 = 99999; Sheet 2 cell C3 = Excel N/A error
The intended return value in this case for (a) would be "Design" since the number is within the inclusive range on sheet 2, the intended value for return value for case (b) would be "Art", and the intended return value for case (c) would be an error because this doesn't fall into any of the ranges provided.
I tried Vlookups, lookups, and index match to no avail. The Lookup function somewhat worked, but didn't have an upper bound so if there was any errors it would just return the last item on the list (ie. sheet 2 column C).
Help is greatly appreciate!
Regards,
You can search using Vlookup, setting the rangelookup to false so that you get the closest match on the lower range column. Tell the lookup to return the upper range column, and if it is more than the value you are looking for, then you got what you needed, otherwise give a null. So in sheet 1, cell a2, you'd have something like:
=if(vlookup(a1,Sheet2!a1..c3,2,false) >= a1, vlookup(a1,Sheet2!a1..c3,3,false), "")
This means you are looking up in the column a of Sheet 2, for the closest number that is lower than the contents of a1 in Sheet 1. Once found, the value in column b is returned and you then compare it to a1 again, to make sure that a1 is in the range (the value in sheet 2, column b is greater than or equal to it). If it is, you do the lookup again, but this time return the column c from sheet 2, which is your return value. If the first lookup did not find something that was in the range, then this returns a blank string.
If you want to watch a vid or two..
Video 1
Video 2
Video 3
I can do this manually but I'm sure there is a formulaic way to do this.
Here is the data :
Column-A Column-B Column-C
C Y
D
E Y
F
E Y
What I want to do is in 2 steps :
a.) Select all values in Column-A, where the corresponding value in Column-B is "Y".
b.) From the data selected from Column-A above, select only the unique values and put them in Column-C
c.) Hence the data in Column-C for the above data will be "C" & "E"
Any pointers ?
Here's one option assuming you have excel 2007
Put this formula in C1
=IFERROR(INDEX(A1:A5,MATCH("Y",B1:B5,0)),"")
then this one in C2 copied down
=IFERROR(INDEX(A$1:A$5,MATCH(1,INDEX((B$1:B$5="y")*(COUNTIF(C$1:C1,A$1:A$5)=0),0),0)),"")
You can do it in earlier versions but it requires some longer formulas to ensure that you don't get error values once valid matches are exhausted
Explanation:
Formula 1 uses MATCH to find the position of the first "y" in B1:B5, then INDEX returns the relevant value from A1:A5. If your columns were the other way round you could use VLOOKUP, INDEX/MATCH is a standard way to do a "left lookup".
Formula 2 uses MATCH to find the position of the first row where 2 conditions are satisfied, B1:B5 = "y" and A1:A5 <> a value already found. The values already found are in column C above so the COUNTIF function looks at the cells above and does a count for each value in column A within that range above (which expands as you drag the formula down) - a count of zero means that that value hasn't already been selected. Once MATCH identifies the row number INDEX takes the value from that row in column A.