I am building a personal trading journal with a very limited knowledge of spreadsheets formula, and decided to ask here after several failed attempts.
I want to achieve this:
Trade Result (column A)
Trading Day (column B)
Win
Monday
Loss
Tuesday
Win
Monday
Win
Tuesday
Loss
Wednesday
Loss
Wednesday
Win
Monday
Win
Monday
Loss
Friday
From above, we know that the day with the most wins: Monday.
Day with the most losses: Wednesday
How do I achieve that Monday for the day with the most wins, and Wednesday for the day with the most losses?
Appreciate the help. Thank you very much.
Try below formula-
=INDEX(SORT(({$B$2:$B$10,COUNTIFS($B$2:$B$10,$B$2:$B$10,$A$2:$A$10,C3)}),2,0),1,1)
use:
=ARRAY_CONSTRAIN(SORTN(QUERY({A:B},
"select Col1,Col2,count(Col2)
where Col1 is not null
group by Col1,Col2
order by count(Col2) desc
label count(Col2)''"), 9^9, 2, 1, 0), 9^9, 2)
Related
I tried using
=INDEX(GOOGLEFINANCE("NASDAQ:MSFT","price",TODAY(), 2),2,2)
And saw that on some days (e.g. 12/6/2021, a Saturday) the function failed to return value. I assume that it is because there was no trading on that day.
Is there a way for me to pick the last value of a stock prior to that day? (e.g. If I calculate on a Saturday or on a Sunday with an American stock I would get Friday's value, Thursday for an Israeli stock etc.)
I am not aware of a way for GOOGLEFINANCE to automatically adjust for no trading days.
One way to do it is to get the "price" data for the last 7 days (to be safe) and then query that data to get the "price" value next to the max date.
This formula works for me:
=INDEX(QUERY(GOOGLEFINANCE("NASDAQ:MSFT","price", TODAY()-7, TODAY()),"select Col1, Col2 order by Col2 desc",1), 2, 2)
You can use the formula below, in the cell that you want the price to be.
=INDEX(GOOGLEFINANCE(A5;"price";$B$2);2;2)
Where A5 contains the stock symbol, like CMI, JNJ, NEE or whatever.
And the B2 contains the following formula:
=if(weekday(B1)=2;B1-3;if(weekday(B1)=1;B1-2;B1-1))
Finally, B1 is just =today().
This will adjust the day for weekdays only. So if it is Saturday, Sunday or Monday, it will give you the price of the stock on Friday.
Basically it will give the last closing price on business days.
Best regards.
I am trying to observe historical trends on customer acquisitions (new and returning) and am looking to use a formula to automate it for me.
Essentially, I am looking to determine the average amount of new customers we acquire on a specific day, specific week, and specific month. For example: what are the average customers we have acquired every Monday for the past 6 months, or what is the average number of customers we acquire the first week of every month?
Solution:
You can use the date operators in your QUERY statement to filter by month, week, or even day of week.
Examples:
every Monday for past 6 months
=query(A1:B, "select avg(B) where datediff(todate(now()),todate(A)) < 180 and dayofweek(A) = 2", 1)
first week of every month
=query(A1:B, "select month(A),avg(B) where day(A) <= 7 group by month(A) offset 1", 1)
You would need to tweak the sample queries to cover your data range and which columns do you need to average and compare.
References:
QUERY()
Query Language Reference | Scalar Functions
In Google Sheets, I'm trying to add up the hours (column F) for each week and automatically select the correct date range (Monday to Sunday). The start date may be in the middle of a week, and I want it to end the Sunday after the start date, then repeat the cycle until it's not populated. For example, Week1 is from Thursday to Sunday, and the following Monday to Sunday needs to Week2, etc.
If this is a duplicate I apologize; I couldn't find anything that answered it.
Example file
try:
=ARRAYFORMULA(QUERY({WEEKNUM(A2:A22, 2), F2:F22},
"select sum(Col2)
where Col2 is not null
group by Col1
label sum(Col2)''"))
I am trying to take the output of the ArrayFormula in the top answer of this previous question, where the output is days of the week, and I want to output them in the proper order (Sunday, Monday, ..., Saturday).
Currently, when I use this formula I get the order Friday, Monday, Saturday, Sunday, Thursday, Tuesday, Wednesday. I have tried using the "order by" clause listing the days of the week in order order by("Sunday", "Monday", ..., "Saturday" without success.
My formula right now is =QUERY({H:H,H:H},"select Col1, count(Col2) where Col1 != '' group by Col1 label count(Col2) 'Number of Calls'",1).
A sanitized version of the data I am attempting to use is here. This data is over the course of one year. It has also been edited to include the two solutions I have so far for reference of future viewers.
Is it currently possible to do the ordering of the days within the Query? If not, what is the best way of going about getting the correct order.
I can't edit your sheet, but this is what I suggest. I don't understand why you have columns D-G, but I will assume you have a reason and work with what you have. First, change H2 to =weekday(F2) and copy it down to H66 (last row). This will return the number of the day of the week (Sunday=1, Monday=2...Saturday=7). Then in I2-I8 fill in the days of the week in the order Sunday through Saturday. In J2 put:
=COUNTIF($H$2:H,"=1")
for Sunday. In J3 put:
=COUNTIF($H$2:H,"=2")
for Monday. And so on through Saturday. That should do it.
Is it possible to drag a repeating pattern of Tuesdays and Fridays repeating in Google Sheets? The type of output I'm looking for would be this:
Tuesday, June 2, 2015
Friday, June 5, 2015
Tuesday, June 9, 2015
Friday, June 12, 2015
...
and then drag down to continue the pattern...
When I do it now, it continues incrementing by he number of days between Tuesday and Friday.
Thanks!
Maybe you can try a formula:
=query(ArrayFormula({(date(2015,6,2)+row(A1:A1000)-1), weekday(date(2015,6,2)+row(A1:A1000)-1,2)}), "select Col1 where Col2 matches '"&JOIN("|", 2, 5)&"' limit 10")
where the date() function holds the starting date
and the limit part limits the output to whatever number you want.
See if that works ?
EDIT: If you only want the tuesdays and fridays from the list of dates in col A, try:
=filter(A2:A, (WEEKDAY(A2:A)=3)+(WEEKDAY(A2:A)=6))
Then copy the output and paste in col A as 'values only'.