excel formula to caluculate the first value - excel-formula

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

Related

Returning a specific value from a table

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)

Excel: How to find highest value in range based on adjacent cells with the same value

I have a column A with names (with duplicates), column B with language codes, and column C with numeral values.
I am struggling to make a formula that would find the highest value in column C, but only for those rows that have the same name – and return the value of column B for the row with that highest value for each unique name in column A. The output should be in another columns, like this:
I think this is what you're looking for:
=INDEX($B:$B,MAX(IF(($C:$C=MAXIFS($C:$C,$A:$A,$E2))*($A:$A=$E2),ROW($C:$C),"")))
Enter the formula in cell F2 with ctrl + shift + enter since it's an array-formula.
I search for the maximum value in column C if the value in column A equals the value in the cell in column E on the same row.
Then I check whether each value in column C equals that maximum value and check whether the value in column A equals the value in column E. If both are true return the row numbers of these en search for the maximum value of these row numbers.
The outcome is the row number of the maximum value that equals the name you searched for.
Using index results in the position of that row number in the desired column (B).
If you're using office 365 you can type =UNIQUE(A:A) in cell E2 to get the unique names listed (prior to adding the formula mentioned above in F2

Excel - compare 2 lists [duplicate]

In Excel, I'm trying to do the following:
Where sheet1 column 1 = sheet2 column 2, return the value in sheet2 column D
I'm stumbling on how to do this as every example I've found seems to use the column index value of the sheet containing the formula. (i.e., sheet1)
I want: VLOOKUP(sheet1!A1,sheet2!A2:A11696,sheet2!4,FALSE)
I can only: VLOOKUP(sheet1!A1,sheet2!A2:A11696,4,FALSE)
After reading other threads, I see people seem to recommend using INDEX. So I tried
=INDEX(sheet2!A2:A11696, MATCH(sheet1!A1004,sheet2!D:D,FALSE))
This doesn't work either.
Your VLOOKUP only references one ccolumn, It should be 3. And start in Column B
VLOOKUP(sheet1!A1,sheet2!B2:D11696,3,FALSE)
The First Criterion is the what to lookup, sheet1!A1
The second is the range in which the value to find and the value to return is found. The first column of the range must be the column in which the criteria will be found. As per sheet1 column 1 = sheet2 column 2 that would then start the range in Column B.
And since the value you want in Column D Column D must be included in the range.
The Third is in which column of the range is the value. It is not the column number itself, but the relative column number, in this case it is the third column in the Range sheet2!B2:D11696.
The forth forces an exact match or relative match. FALSE forces an Exact Match.
If you are going to use an INDEX/MATCH then:
=INDEX(sheet2!D2:D11696, MATCH(sheet1!A1,sheet2!B2:B11696,0))
The MATCH part returns the relative row number where A1 is found in Column B on sheet two.
Then using this number in the INDEX it finds that relative row number in the range in Column D and returns that value.
The 0 in the MATCH() tells the Match to look for the exact match.
The INDEX/MATCH function pair should look like this.
=INDEX(sheet2!D:D, MATCH(sheet1!A1, sheet2!B:B, 0))
In a more generic sense, the INDEX/MATCH method is used as follows:
=INDEX(A:A, MATCH(B1, C:C, 0))
Where:
A:A = The row or column containing the value you need to find.
B1 = The value you are using to reference the index (location) of the value you're trying to find.
C:C = The row or column containing the value that matches B1. The size of this range should match the size of A:A, though it is not required.
0 = This just means "Match exactly". -1 would mean "match if B1 is less than C:C. 1 would mean "match if B1 is greater than C:C.

Summing the values of one column only up to the depth of another column

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)))

VLOOKUP vs INDEX

In Excel, I'm trying to do the following:
Where sheet1 column 1 = sheet2 column 2, return the value in sheet2 column D
I'm stumbling on how to do this as every example I've found seems to use the column index value of the sheet containing the formula. (i.e., sheet1)
I want: VLOOKUP(sheet1!A1,sheet2!A2:A11696,sheet2!4,FALSE)
I can only: VLOOKUP(sheet1!A1,sheet2!A2:A11696,4,FALSE)
After reading other threads, I see people seem to recommend using INDEX. So I tried
=INDEX(sheet2!A2:A11696, MATCH(sheet1!A1004,sheet2!D:D,FALSE))
This doesn't work either.
Your VLOOKUP only references one ccolumn, It should be 3. And start in Column B
VLOOKUP(sheet1!A1,sheet2!B2:D11696,3,FALSE)
The First Criterion is the what to lookup, sheet1!A1
The second is the range in which the value to find and the value to return is found. The first column of the range must be the column in which the criteria will be found. As per sheet1 column 1 = sheet2 column 2 that would then start the range in Column B.
And since the value you want in Column D Column D must be included in the range.
The Third is in which column of the range is the value. It is not the column number itself, but the relative column number, in this case it is the third column in the Range sheet2!B2:D11696.
The forth forces an exact match or relative match. FALSE forces an Exact Match.
If you are going to use an INDEX/MATCH then:
=INDEX(sheet2!D2:D11696, MATCH(sheet1!A1,sheet2!B2:B11696,0))
The MATCH part returns the relative row number where A1 is found in Column B on sheet two.
Then using this number in the INDEX it finds that relative row number in the range in Column D and returns that value.
The 0 in the MATCH() tells the Match to look for the exact match.
The INDEX/MATCH function pair should look like this.
=INDEX(sheet2!D:D, MATCH(sheet1!A1, sheet2!B:B, 0))
In a more generic sense, the INDEX/MATCH method is used as follows:
=INDEX(A:A, MATCH(B1, C:C, 0))
Where:
A:A = The row or column containing the value you need to find.
B1 = The value you are using to reference the index (location) of the value you're trying to find.
C:C = The row or column containing the value that matches B1. The size of this range should match the size of A:A, though it is not required.
0 = This just means "Match exactly". -1 would mean "match if B1 is less than C:C. 1 would mean "match if B1 is greater than C:C.

Resources