As I manage my stock investment portfolio in Google Sheets, I need to see its evolution over time, for example, in the last year. However, the computation for daily evolution is resource-consuming and might cause performance issues for the spreadsheet. As an alternative, I compute only the weekly evolution of the investment portfolio for the last year. For each week, I compute only the portfolio's value at the end of the Friday. For that, I need a Google Sheets formula to return the last Friday for a given date. This post explains how I do that with the WEEKDAY formula in Google Sheets.
Table of Contents
Concept
To find the last Friday from a date, I need to determine how many days I need to subtract from that date.
- If the date is Saturday, the last Friday is 1 day before it.
- If the date is Sunday, the last Friday is 2 days before it.
- If the date is Monday, the last Friday is 3 days before it.
- If the date is Tuesday, the last Friday is 4 days before it.
- If the date is Wednesday, the last Friday is 5 days before it.
- If the date is Thursday, the last Friday is 6 days before it.
- If the date is Friday, the last Friday is 7 days before it.
In Google Sheets, the WEEKDAY function returns a number representing the day of the week for a given date. More specifically, if the type is 2, Monday is the first day of the week, and its value is 1, while Sunday is the last day of the week, and its value is 7.
I made a small schema below to explain how to calculate the number of days to subtract based on the WEEKDAY function:
Formula and demo
Here is the final formula that can be applied on any date to find out the last Friday.
=TODAY()-IF(WEEKDAY(TODAY(),2)>5,WEEKDAY(TODAY(),2)-5,2+WEEKDAY(TODAY(),2))
Conclusion
In the next posts, I will explain how to compute the weekly evolution of a stock investment portfolio in Google Sheets. The formula to find last Friday for a given date presented in this post will be useful.
Disclaimer
The post is only for informational purposes and not for trading purposes or financial advice.
Feedback
If you have any feedback, question, or request please:
- leave a comment in the comment section
- write me an email to allstacksdeveloper@gmail.com
Support this blog
If you value my work, please support me with as little as a cup of coffee! I appreciate it. Thank you!
Share with your friends
If you read it this far, I hope you have enjoyed the content of this post. If you like it, share it with your friends!
Comments
Post a Comment