Minima Elementwise in Excel - excel

I have two columns of data: A and B.
I need a column C with elementwise minima between A and B data.
For instance:
If I put in C:
= MIN ($A$1:$A$3; $B$1:$B$3)
Then I get a single number, the minimum of all data (in our case 1).
What can I do?

Can't you just use
=IF(A1:A3<B1:B3,A1:A3,B1:B3)
Or, a little fancier (depending if available to you):
=BYROW(A1:B3,LAMBDA(arr,MIN(arr)))
This will spill all minima when using Microsoft365.

You were almost there.You just need your formula to be =MIN(A1:B1) at row 1 and then drag down.
Notice there are not $ so we are using relative references. That way you can get minimun value between A and B values at same row, not all values.
Switch between relative, absolute, and mixed
references

In cell C1, you put following formula:
=MIN(A1;B1)
You select cell C1, you put your mouse-cursor in the right-bottom part of cell C1 until the cursor changes in a small cross, you start dragging and you drop once cell C3 is filled.
You will see following formula:
In cell C2:
=MIN(A2; B2)
In cell C3:
=MIN(A3; B3)
As you see, there's no need to use absolute references (the ones with the dollarsigns) you're using.

Related

Getting the row number of the N smallest value in a list using the small function

I'm trying to dynamically sort a list of values for a helper column that looks something like this. I want to return the row number of the smallest value, then the next smallest, etc. The column on the right is what I want my output to look like. The formula I have so far is =ROW(SMALL(A$1:A$15, A$2:A2) but excel won't let me enter it.
In Excel O365 you could use a single formula in C1 using SORTBY:
=SORTBY(IF(A:A<>"",ROW(A:A),""),A:A,1)
In B1 enter 1. In B2 enter:
=IF(A2="",9999,IF( COUNTIF($A$1:A1,A2)=0,A2,A2+COUNTIF($A$1:A1,A2)/100))
and copy downward.
In C1 enter:
=MATCH(SMALL(B:B,ROWS($1:1)),B:B,0)
and copy downward:
NOTE:
Column B de-conflicts duplicate items in column A and handles the blanks in column A.
To limit the length of column C, use this instead in C1
=IF( ROWS($1:1)>COUNT(A:A),"",MATCH(SMALL(B:B,ROWS($1:1)),B:B,0))

Excel - Offset to last non-blank cell

From my research, when a bunch of cells are merged, you can only reference the first row and first column of the merged cells. EG. if A1:A3 are merged, then I can only access the data using A1 only, and A2 and A3 returns 0.
Now let's say I have a column B that has a formula that calculates based on values in column A. If I drag this formula down, then B2 and B3 will end up using value of 0, when they should be using value in A1.
Effectively, what i want to do is "if the cell in column A (of this row) is blank, then use the last non-blank value going upwards".
I know this will need to combine a couple of formulas, but I can't figure out how to create this. For a start, I can use the Offset function to "go up", but the difficult part here is how to find the previous non-blank cell?
I also tried combing OFFSET with COUNTA (see https://www.exceltip.com/other-qa-formulas/get-the-value-of-the-last-non-blank-cell-in-a-column-in-microsoft-excel.html), but this doesn't work if this occurs multiple times.
Easiest way is to use a helper column:
In B2 write
=IF(NOT(ISBLANK(A2)),0,B1+1)
and in C2 write
=OFFSET(A2,-B2,0)
Edit: actually... the solution without helper column is even easier! Write in B2:
=IF(ISBLANK(A2),B1,A2)
To avoid the helper column, you can use the INDEX + AGGREGATE functions:
=INDEX($A$1:A1,AGGREGATE(14,6,($A$1:A1<>"")*ROW($A$1:A1),1))

Drag formula down and change the reference of the column (index+match)

I need help with the following formula:
=INDEX(Sheet2!A2:A11,MATCH(Sheet1!Q5,Sheet2!C2:C11,0)+0)
(this part needs to change column references: Sheet2!C2:C11,0)+0)
I need to change the column reference whenever I'm dragging it down. I tried this:
=INDEX(Sheet2!$A$2:$A$12,MATCH(Sheet1!Q4,OFFSET(Sheet2!$A$2:$A$12,0,ROW(O$4:O4)-1),0)+0)
but it always comes up with #N/A
I tried solution from other topics but couldn't find one that uses index and match.
PS. My formula starts from cell O5
Can you advise please?
Much obliged
In general, if you want to change the column reference when dragging down, use a combination of INDEX and ROW, e.g.
= INDEX($1:$1,ROW())
This will grab values further to the right in the first row as the formula is dragged down.
You can also modify this to have INDEX return a range (instead of just a single cell) to be used as part of another formula, e.g.
= INDEX($1:$5,0,ROW())
This returns a 5x1 array which shifts over to the right as the formula is dragged down. (The 0 in the above formula indicates to select all of the rows in the $1:$5 range.)
In your formula, you can try replacing this:
Sheet2!C2:C11
With this:
INDEX(Sheet2!$2:$11,0,ROW()+<offset>)
Where <offset> is the necessary offset that you need.
If your formula starts in O5 and you want that first formula to grab the C column, I imagine that <offset> should be -2. This is because ROW() of O5 is 5, but you want that cell to grab the 3rd column (so you need to subtract 2). Then when you drag down to O6, that part of the formula would evaluate to Sheet2!D2:D11, and in cell O7, it would evaluate to Sheet2!E2:E11, etc.
So your final formula should be:
= INDEX(Sheet2!A2:A11,MATCH(Sheet1!Q3,INDEX(Sheet2!$2:$11,0,ROW()-2),0)+0)

Reference every second cell in Excel formula

I currently have a formula like this:
=ROUND((('Sheet1'!D77-'Sheet1'!D75)/'Sheet1'!D75)*100,1)
with the next cell below that:
=ROUND((('Sheet1'!D79-'Sheet1'!D77)/'Sheet1'!D77)*100,1)
What I want is to drag the formula down and to reference every 2nd cell. So for e.g. it should go from referencing D79-D77 to D81-D79 (and not D80-D78) etc. How can I go about doing this?
Thanks
You can also do it with INDEX, multiplying the row that the formula is in relative to the first row by 2 and adding it to either 75 or 77:
=ROUND(((INDEX(Sheet1!D:D,77+(ROWS(A$1:A1)-1)*2)-INDEX(Sheet1!D:D,75+(ROWS(A$1:A1)-1)*2))/INDEX(Sheet1!D:D,75+(ROWS(A$1:A1)-1)*2))*100,1)
Oh, this is interesting.
Assuming you have your first cell at
B1
and the value you are looking into is in column C, starting at cell
C1
To do this, you need to have number at column A. Start with number 1, counting up. (you may include this in dragging)
So side by side, you have number column at A, while the absolute percentage at column B, and values at C (in alternating row).
I did the arithmetic progression, combined with the address and indirect functions to do the task.
where:
an = a1 + (n-1) * d
in B1, the code should look like this:
=(INDIRECT("C"&(3+(A1-1)*2))-INDIRECT("C"&(1+(A1-1)*2)))/INDIRECT("C"&(1+(A1-1)*2))
I guess this should do it.
Cheers..

Creating a column formula in excel, changing only one variable

I have a very basic excel file for looking at the cost of shares and calculating a profit/loss %.
I have the initial purchase price in cell E3 and I have the current share price in F3. I have calculated the percentage profit/loss in G3 by the following formula
=(F3/E3)*100 - 100
What I now want is to be able to apply this formula to the whole G column as I enter a new share price into the F column, it will use E3 as a constant in the formula to calculate daily profit/loss. So the new formula I want is effectively;
=(Fi/E3)*100 - 100
Where Fi = F3, F4, F5, F6 and so on...
I have tried dragging the cell down to extend the formula, which works to an extent but it does not keep E3 constant so I get a divide by zero error.
Any suggestions? Thanks
Start with =(F3/E$3)*100 - 100. The $ is an absolute anchor that tells the formula not to change the 3 in E$3 when filled down.
If there is no value in column F, you can have the result returned as a zero-length string (e.g. "") which will make the cell in column G that holds the formula look blank.
=IF(LEN(F3), (F3/E$3)*100 - 100, "")
Use an absolute reference for E3 in the formula:
$e$3
This will lock the reference if you drag the cell down.
The other way around, if you want to lock the character:
=(F3/$E3)*100 - 100

Resources