MODE with SUMPRODUCT formula - google-sheets

I am trying to find a mode of weekdays (Monday, Tuesday, etc.) within a date range by using the formula:
=ARRAYFORMULA(MODE(SUMPRODUCT(--(AgendaData!$A:$A>=A$6),--(AgendaData!$B:$B<=B$6),AgendaData!$F:$F)))
The error reads: "MODE cannot produce a result. No values occur more than once."
I think it has something to do with the F column being in text format. I want the result to show the mode of the weekday in text. I wonder what I am doing wrong here.

You can find the mode of text values by converting them to numbers, finding the mode, and converting back. It's convenient to use a three-column lookup table for this, e.g.,
Monday 1 Monday
Tuesday 2 Tuesday
Wednesday 3 Wednesday
Thursday 4 Thursday
Friday 5 Friday
Saturday 6 Saturday
Sunday 7 Sunday
Let's say this table is in columns I:K, and your data is in column F. Then the following finds its mode:
=vlookup(mode(arrayformula(iferror(vlookup(F:F, I:J, 2, false)))), J:K, 2)
Here, arrayformula(iferror(vlookup... is conversion to numeric, using the part I:J of the table, and ignoring blank cells and anything that isn't a day of week. After mode is applied, vlookup converts the number back to text using the part J:K of the table.

To check it out, you may use formula:
=filter(AgendaData!$F:$F,AgendaData!$A:$A>=A$6,AgendaData!$B:$B<=B$6)
You'll see all matching values from column F and will know exactly if some values occur more than once.

Related

count how many specific days are in a time period

I want to count say how many Mondays we have from 2022-02-01 - 2022-03-01. I found smth like this:
=SUMPRODUCT(WEEKDAY(B4:C4)=2) - B4 and C4 are the dates
But it returns 0. I assume it only checks if specific date is the specific day. Any ideas how I can do this but for a date range? So how count how many Mondays there are in February
I also found this
=NETWORKDAYS.INTL(B4;C4;"1000000")
but this returns 25
You can take advantage of the NETWORKDAYS.INTL function by using the string method to make all the days as weekend except for Monday.
The String method states:
weekends can be specified using seven 0’s and 1’s, where the first number in the set represents Monday and the last number is for Sunday. A zero means that the day is a work day, a 1 means that the day is a weekend. For example, “0000011” would mean Saturday and Sunday are weekends.
In this case since you only want to know the Mondays, the string would be "0111111" and the function would look like:
=NETWORKDAYS.INTL(StartDate,EndDate,"0111111")
I think this is right. It's counting inclusively so you would get five Mondays starting on Monday 7th Feb 2022 and ended on Monday 7th March 2022 for example.
=floor((B2-(A2+7-weekday(A2,12)))/7)+1
where A2 and B2 contain the start date end end date.
Obvs nul points for me again but for the record this could be generalised if you put the day number in C2 (e.g. 1 if you want to find Sundays, 2 for Mondays):
=floor((B2-(A2+7-weekday(A2,10+C2)))/7)+1

How to get last closing price of a stock in google finance (In a non-trading day)

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.

Highlight Duplicate Within 24 hours timestamp but a different date

I am trying to figure if the following can be done. If there are duplicate names in the B column then it will see if the date and time were within 24 hours of each other in the A column, if so it will highlight the cell yellow.
Currently, the formula I have will only highlight if it was on the same date. Is there a way I can add to the formula to all take into account time? So that if one response is on 5/20/20 at 17:00 and the next duplicate name is at 5/21/20 at 16:00 then the cell would be highlighted.
Here is the formula I am using the just highlights if it is within the same date:
=ARRAYFORMULA(COUNTIFS(B:B, B2, DATEVALUE(A:A), DATEVALUE(A2))>1)
I am not sure if something like this is possible. I am guessing that the formula would have to compare both datevalue and timevalue. Any help would be appreciated.
Instead of DATEVALUE you can use TO_PURE_NUMBER
This will return you the number of days from January 1, 1900 including the fraction for past hours and minutes opposed to DATEVALUE that rounds the value down to an integral day number.
Sample:
This allows you to calculate the real difference time between your timestamp.
For example like this:
=ARRAYFORMULA(or(COUNTIFS(B:B, B2, TO_PURE_NUMBER(A:A), ">"&TO_PURE_NUMBER(A2)-1, TO_PURE_NUMBER(A:A), "<"&TO_PURE_NUMBER(A2))>0,COUNTIFS(B:B, B2, TO_PURE_NUMBER(A:A), "<"&TO_PURE_NUMBER(A2)+1,TO_PURE_NUMBER(A:A), ">"&TO_PURE_NUMBER(A2))>0))

How to auto create a Month calendar in google sheets. Where first day of the month start in the colum of the (name)day

I want to create a calendar like in the second image. But I can not figure out how to start the first column is a monday. So I fill it by 'hand' like in the first image.
I tried to create it automatic. Starting with the first day of the month and add one day the next columns like in the second picture:
How I want it to look like:
How it is currently looking:
Google sheets example
I was solving the same problem for my bussiness, and I think I got the answer.
Your first task is to determine the first "calendar monday" of the month.
First, build the first day of the corresponding month:
[B2] =DATE(YEAR(A1); MONTH(A1); 1)
Then, get the WEEKDAY of the corresponding first day. The second argument represents what day your week starts with:
If type is 1, days are counted from Sunday and the value of Sunday is 1, therefore the value of Saturday is 7.
If type is 2, days are counted from Monday and the value of Monday is 1, therefore the value of Sunday is 7.
If type is 3, days are counted from Monday and the value of Monday is 0, therefore the value of Sunday is 6.
In my case, we count the week starting from Monday. This means when the first day of the month lands on Monday, the return value will be 0.
[C2] =WEEKDAY(B2; 3)
The number you get represents how many days you need to substract from the initial date to get the first "calendar monday" of the month:
[D2] =B2 - C2
This date is what you are looking for. The final formula:
[A3] =DATE(YEAR(A1); MONTH(A1); 1) - WEEKDAY(DATE(YEAR(A1); MONTH(A1); 1); 3)
The rest of the days, simply add 1 to each preceding date.
[A4] =A3 + 1
[A5] =A4 + 1
And so on.
Secondly, set the Number Format on the calendar cells to just show the day.
Format -> Number -> More Formats -> More Date and Time Formats.
Select just the day from the drop down.
Finally, use conditional formatting to "hide" the values that don't match the initial date
Use a custom formula for the formatting, as follows:
=MONTH(A3) <> MONTH(A1)
Apply to the calendar range. This will format dates that don't belong to the current date, so make sure to paint that white.
And that's about it. Good luck!

Show only the current Week

I am working with Google sheets, and the Form responses that get poured into it. I am wondering if there is a way to show the CURRENT work week? What I mean by this is a sheet that shows this Friday:
MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY
124 123 193 -- 234
344
But then the next Monday:
MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY
088 -- -- -- --
Is this possible, or is it to much for google sheets?
It's certainly possible. To begin with, I would put dates under Monday, Tuesday, etc: this simplifies subsequent computations, and is also helpful when reading the data. This would go under "Monday": it returns the Monday of the current workweek:
=today()-weekday(today())+2
Here +2 compensates for subtraction when the date is Monday (which is numbered 2). The other days of the week can be obtained by adding 1 to Monday (=A2+1), or directly by using =today()-weekday(today())+3 and so on.
Then you can pull data from the form sheet using functions such as query, filter, vlookup, ... For example, this formula returns the 3rd column from Form Responses 1 where the date is nearest to the content of A2 (current Monday)
=vlookup(A2, 'Form Responses 1'!A:A, 3)
A possible issue here is that Form Responses record both date and time, so the "nearest" record may be from 11:50pm of previous day. One way to solve this is to use filter:
=filter('Form Responses 1'!C:C, floor('Form Responses 1'!A:A) = A2)
This returns all C column entries from the form where the date in the A column matches the content of A2.

Resources