Date issue?

tigerzen

Board Regular
Joined
Mar 8, 2023
Messages
209
Office Version
  1. 365
Platform
  1. Windows
Trying to get this to work, column K is the issue, is the date syntax right for YTD?

Stock+Percent+Change+Example.xlsx
ABCDEFGHIJKLM
3Helper Data
4StockCurrentYTD1 Year5 YearsBegin Yr1 Yr Ago5 Yrs Ago
5MICROSOFT CORPORATION (XNAS:MSFT)$ 290.73#VALUE!#VALUE!(8%)215%#VALUE!$ 314.97$ 92.33
6APPLE INC. (XNAS:AAPL)$ 168.88#VALUE!#VALUE!(5%)294%#VALUE!$ 178.44$ 42.90
7TESLA, INC. (XNAS:TSLA)$ 876.35#VALUE!#VALUE!130%4,481%#VALUE!$ 381.81$ 19.13
8NETFLIX, INC. (XNAS:NFLX)$ 386.67#VALUE!#VALUE!(1%)34%#VALUE!$ 391.50$ 288.94
Stocks
Cell Formulas
RangeFormula
C5:C8C5=B5.Price
D5:D8D5=C5/K5-1
E5:E8,G5:G8,I5:I8E5=IF(D5<0,"▼","▲")
F5:F8F5=C5/L5-1
H5:H8H5=C5/M5-1
K5:K8K5=INDEX(STOCKHISTORY($B5,"1/1/" & YEAR($C$2),"1/31/"& YEAR($C$2)),2,2)
L5:L8L5=INDEX(STOCKHISTORY($B5,DATE(YEAR($C$2)-1,MONTH($C$2),DAY($C$2)),DATE(YEAR($C$2)-1,MONTH($C$2),DAY($C$2)+30)),2,2)
M5:M8M5=INDEX(STOCKHISTORY($B5,DATE(YEAR($C$2)-5,MONTH($C$2),DAY($C$2)),DATE(YEAR($C$2)-5,MONTH($C$2),DAY($C$2)+30)),2,2)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
1:1048576Expression=A1="▲"textNO
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hi,
You could test the combination :
Excel Formula:
EDATE(TODAY(),-11)
Excel Formula:
TODAY())
 
Upvote 0
For some reason the spreadsheet didn't copy completely, here is the complete sheet

Stock+Percent+Change+Example.xlsx
BCDEFGHIJKLM
1
2Current Date4/04/2023
3Helper Data
4StockCurrentYTD1 Year5 YearsBegin Yr1 Yr Ago5 Yrs Ago
5MICROSOFT CORPORATION (XNAS:MSFT)$ 290.73#VALUE!#VALUE!(8%)215%#VALUE!$ 314.97$ 92.33
6APPLE INC. (XNAS:AAPL)$ 168.88#VALUE!#VALUE!(5%)294%#VALUE!$ 178.44$ 42.90
7TESLA, INC. (XNAS:TSLA)$ 876.35#VALUE!#VALUE!130%4,481%#VALUE!$ 381.81$ 19.13
8NETFLIX, INC. (XNAS:NFLX)$ 386.67#VALUE!#VALUE!(1%)34%#VALUE!$ 391.50$ 288.94
Stocks
Cell Formulas
RangeFormula
C2C2=TODAY()
C5:C8C5=B5.Price
D5:D8D5=C5/K5-1
E5:E8,G5:G8,I5:I8E5=IF(D5<0,"▼","▲")
F5:F8F5=C5/L5-1
H5:H8H5=C5/M5-1
K5:K8K5=INDEX(STOCKHISTORY($B5,"1/1/" & YEAR($C$2),"1/31/"& YEAR($C$2)),2,2)
L5:L8L5=INDEX(STOCKHISTORY($B5,DATE(YEAR($C$2)-1,MONTH($C$2),DAY($C$2)),DATE(YEAR($C$2)-1,MONTH($C$2),DAY($C$2)+30)),2,2)
M5:M8M5=INDEX(STOCKHISTORY($B5,DATE(YEAR($C$2)-5,MONTH($C$2),DAY($C$2)),DATE(YEAR($C$2)-5,MONTH($C$2),DAY($C$2)+30)),2,2)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
1:1048576Expression=A1="▲"textNO
 
Upvote 0
Hi again,
Why haven't you tested for cell K5
Excel Formula:
=INDEX(STOCKHISTORY($B5,EDATE(TODAY(),-11),TODAY(),2,2)
 
Upvote 0
Hi again,
Why haven't you tested for cell K5
Excel Formula:
=INDEX(STOCKHISTORY($B5,EDATE(TODAY(),-11),TODAY(),2,2)
Hi James, thanks for that suggestion. I now get a value but it's a spilled range containing 2 entries ie a cell containing a date and next it the correct stock value.
By the way any ideas as to why my original formula doesn't work?
 
Upvote 0

Forum statistics

Threads
1,223,631
Messages
6,173,465
Members
452,516
Latest member
archcalx

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