Need Formula To Reference Last Row Of Data & Calculate For Current Row

Dhira

Board Regular
Joined
Feb 23, 2006
Messages
81
Office Version
  1. 2021
Platform
  1. Windows
Thanks to everyone who helped in the last question here.

I needed it for this question:
How do I use a formula to calculate a new cell based on the last row where data was entered?
See below:


Data.xlsx
ABCDEF
1ROI %Action$ SOLD# SOLDROI % Difference$ TO BUY
229.80%Hold
329.70%Hold
427.70%Hold
528.50%Hold
629.40%Hold
731.80%Sell$1,172.124951
829.80%Hold
929.70%Hold
1027.70%Hold
1128.50%Hold
1229.40%Hold
1314.20%Buy17.60%$205.93
1429.70%Hold
1527.70%Hold
1628.50%Hold
1729.40%Hold
1838.40%Sell$764.923231
1929.70%Hold
2027.70%Hold
2128.50%Hold
2229.70%Hold
2321.50%Hold
2418.00%Hold
2516.20%Hold
2614.20%Buy24.20%$185.25
2729.70%Hold
2827.70%Hold
2928.50%Hold
Sheet5


I'd like the "To Buy" column to show the answer only when the condition is met (difference of ROI% at time of sale and current row ROI % being greater than 15%), otherwise, shwoing nothing.
In the above, I'd like to get rid of column D and simply have one formula in Column F that I can drag & copy down.

To wit, the formula structure should basically be:

If Column A (@ row of last sale) - Column A (@ current row) > 15%, Calculate difference between % and multiply it by the dollar amount of last sale (Column C), Else, show nothing (blank).

Appreciate your help.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
I'm getting different results based on your requirements. Rows 23-25 have ROI > 15%, should it be showing?
Book1 (version 1).xlsb
ABCDE
1ROI %Action$ SOLDDifference in ROI$ TO BUY
20.298Hold 
30.297Hold 
40.277Hold 
50.285Hold 
60.294Hold 
70.318Sell$ 1,172.120.00
80.298Hold0.02
90.297Hold0.02
100.277Hold0.04
110.285Hold0.03
120.294Hold0.02
130.142Buy0.18$ 206.29
140.297Hold0.02
150.277Hold0.04
160.285Hold0.03
170.294Hold0.02
180.384Sell$ 764.920.00
190.297Hold0.09
200.277Hold0.11
210.285Hold0.10
220.297Hold0.09
230.215Hold0.17$ 129.27
240.18Hold0.20$ 156.04
250.162Hold0.22$ 169.81
260.142Buy0.24$ 185.11
270.297Hold0.09
280.277Hold0.11
290.285Hold0.10
Sheet7
Cell Formulas
RangeFormula
D2:D29D2=IFERROR(LOOKUP(2,1/($B$2:B2="Sell"),$A$2:A2)-A2,"")
E2:E29E2=LET( ROI_sell,LOOKUP(2,1/($B$2:B2="Sell"),$A$2:A2), IFERROR(IF(ROI_sell-A2>15%,LOOKUP(2,1/($B$2:B2="Sell"),$C$2:C2)*(ROI_sell-A2),""),"") )
 
Upvote 1
I had a different formula starting with E2, but I'm getting the same results as Cubist.

Excel Formula:
=IFERROR(LET(last_row,MAX(ROW($A1:$A$2)*ISNUMBER($A1:$A$2)*($B1:B$2="Sell")),diff, INDIRECT("A" & last_row)-A2, IF(diff>0.15,diff*INDIRECT("C" & last_row), "")), "")
 
Upvote 1
I'm getting different results based on your requirements. Rows 23-25 have ROI > 15%, should it be showing?
Book1 (version 1).xlsb
ABCDE
1ROI %Action$ SOLDDifference in ROI$ TO BUY
20.298Hold 
30.297Hold 
40.277Hold 
50.285Hold 
60.294Hold 
70.318Sell$ 1,172.120.00
80.298Hold0.02
90.297Hold0.02
100.277Hold0.04
110.285Hold0.03
120.294Hold0.02
130.142Buy0.18$ 206.29
140.297Hold0.02
150.277Hold0.04
160.285Hold0.03
170.294Hold0.02
180.384Sell$ 764.920.00
190.297Hold0.09
200.277Hold0.11
210.285Hold0.10
220.297Hold0.09
230.215Hold0.17$ 129.27
240.18Hold0.20$ 156.04
250.162Hold0.22$ 169.81
260.142Buy0.24$ 185.11
270.297Hold0.09
280.277Hold0.11
290.285Hold0.10
Sheet7
Cell Formulas
RangeFormula
D2:D29D2=IFERROR(LOOKUP(2,1/($B$2:B2="Sell"),$A$2:A2)-A2,"")
E2:E29E2=LET( ROI_sell,LOOKUP(2,1/($B$2:B2="Sell"),$A$2:A2), IFERROR(IF(ROI_sell-A2>15%,LOOKUP(2,1/($B$2:B2="Sell"),$C$2:C2)*(ROI_sell-A2),""),"") )
You're right it should show for those rows - my bad for not checking the conditions for those rows.

However my excel sheet is showing "#NAME?" error in column E (The formula contains unrecognized text).
Could that be due to my version of excel? I'm using Microsoft Office Professional Plus 2019....
 
Upvote 0
Your profile says 2021...try this.
Excel Formula:
=IFERROR(IF(LOOKUP(2,1/($B$2:B2="Sell"),$A$2:A2)-A2>15%,LOOKUP(2,1/($B$2:B2="Sell"),$C$2:C2)*(LOOKUP(2,1/($B$2:B2="Sell"),$A$2:A2)-A2),""),"")
 
Upvote 0
I had a different formula starting with E2, but I'm getting the same results as Cubist.

Excel Formula:
=IFERROR(LET(last_row,MAX(ROW($A1:$A$2)*ISNUMBER($A1:$A$2)*($B1:B$2="Sell")),diff, INDIRECT("A" & last_row)-A2, IF(diff>0.15,diff*INDIRECT("C" & last_row), "")), "")
Thanks! That works also!
Your profile says 2021...try this.
Excel Formula:
=IFERROR(IF(LOOKUP(2,1/($B$2:B2="Sell"),$A$2:A2)-A2>15%,LOOKUP(2,1/($B$2:B2="Sell"),$C$2:C2)*(LOOKUP(2,1/($B$2:B2="Sell"),$A$2:A2)-A2),""),"")
Yes sir! That works.
I (like a dork), have 2021 on my laptop & 2019 on my desktop lol. Time to upgrade my desktop.

Thank you both!🙏
 
Upvote 0
Guys, sorry, there's a little glitch in the question.
I know I wrote: "In the above, I'd like to get rid of column D and simply have one formula in Column F that I can drag & copy down."
I meant to say "In the above, I'd like to get rid of column E and simply have one formula in Column F that I can drag & copy down." (which was why it was greyed out) - My bad.

The formulas you gave seem to be calculating whether the text "sell" exists in column B, when it should be checking whether the # of units sold exists in Column D.
If so, then it should calculate using the the % difference should be multiplied by whatever's in Column C. ∴ Column C "$ Sold" & D "# Sold" are both needed.
If you could tweak the formula for the original sheet accordingly, I'd appreciate it.
 
Upvote 0
Book1
ABCDE
1ROI %Action$ SOLD# SOLD$ TO BUY
20.298Hold
30.297Hold
40.277Hold
50.285Hold
60.294Hold
70.318Sell$ 1,172.12$ 4,951.00
80.298Hold
90.297Hold
100.277Hold
110.285Hold
120.294Hold
130.142Buy$ 206.29
140.297Hold
150.277Hold
160.285Hold
170.294Hold
180.384Sell$ 764.92$ 3,231.00
190.297Hold
200.277Hold
210.285Hold
220.297Hold
230.215Hold$ 129.27
240.18Hold$ 156.04
250.162Hold$ 169.81
260.142Buy$ 185.11
270.297Hold
280.277Hold
290.285Hold
Sheet2
Cell Formulas
RangeFormula
E2:E29E2=LET( ROI_diff,LOOKUP(2,1/($D$2:D2<>""),$A$2:A2)-A2, IFERROR(IF(ROI_diff>15%,LOOKUP(2,1/($D$2:D2<>""),$C$2:C2)*(ROI_diff),""),"") )
 
Upvote 0
Solution
Book1
ABCDE
1ROI %Action$ SOLD# SOLD$ TO BUY
20.298Hold
30.297Hold
40.277Hold
50.285Hold
60.294Hold
70.318Sell$ 1,172.12$ 4,951.00
80.298Hold
90.297Hold
100.277Hold
110.285Hold
120.294Hold
130.142Buy$ 206.29
140.297Hold
150.277Hold
160.285Hold
170.294Hold
180.384Sell$ 764.92$ 3,231.00
190.297Hold
200.277Hold
210.285Hold
220.297Hold
230.215Hold$ 129.27
240.18Hold$ 156.04
250.162Hold$ 169.81
260.142Buy$ 185.11
270.297Hold
280.277Hold
290.285Hold
Sheet2
Cell Formulas
RangeFormula
E2:E29E2=LET( ROI_diff,LOOKUP(2,1/($D$2:D2<>""),$A$2:A2)-A2, IFERROR(IF(ROI_diff>15%,LOOKUP(2,1/($D$2:D2<>""),$C$2:C2)*(ROI_diff),""),"") )

Thanks again. You're like the fastest gun in these excel streets. Played around with this for a bit & it's exactly as needed.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top