Google Sheets filter by todays date - google-sheets

I have created a google sheet of sporting events, this then filters to different websites using the ninjatables wordpress plugin.
Not all websites need to display all the games.
The 'Games' sheet contains a list of all the events throughout the year, I then have a query to filter the results into individual sheets for individual sites, displaying only certain sporting events for that site, such as;
Site 1 = Rugby and Football
Site 2 = Football and Basketball
Everything so far works fine.
I am now trying to add a date filter so that games before todays date are no longer visible.
=query(Games!A:Y, "where A > date '"&TEXT(TODAY(),"yyyy-mm-dd")&"' and (F = 'Football') or (F = 'Rugby')",1)
If I change the greater than (>) sign to less than(<), it filters out the results to only show the games before todays date just fine, but for some reason my current query does not filter out games before today.
I have tried changing the formating on my date column on the games sheet (mm/dd/yy, dd/mm/yyyy, yyy-mm-dd, etc) not sure that that has anything to do with it, but couldnt hurt to try.
If anyone could shed any light as to where I may be going wrong it would be greatly appreciated.

Solution:
You can use greater than or equal >= as an operator.
EDIT: Boolean operations are evaluated left to right, so A > date '"&TEXT(TODAY(),"yyyy-mm-dd")&"' and (F = 'Football') are evaluated first, then this is or'd with (F = 'Rugby').
This is fixed by grouping the column F conditions with parenthesis.
=query(Games!A:Y, "where A >= date '"&TEXT(TODAY(),"yyyy-mm-dd")&"' and ((F = 'Football') or (F = 'Rugby'))",1)
This will display entries greater than or equal to today's date, and if column F is (Football or Rugby)
Sample Query:

Related

In Google sheets, can a QUERY statement determine the oldest date in a column, add 6 months to it , then display that range?

Currently, I am having to query the entire set, jot down the oldest date, and then add a GTE (>=) and a LTE (<=) back into the query statement to limit the results to 6 months, like this:
=QUERY(RawData!A1:D, "SELECT * WHERE A = 'N502SY' and C >= date '2020-03-20' and C <= date '2020-09-20' ORDER BY C ASC")
Ideally, the query statement would determine ON ITS OWN what the oldest date is and then display all rows found with that date PLUS all rows that have a date within a 6-month period (from the oldest date).
Have done a ton of google searching to find an answer but have come to the conclusion that QUERY statements may not be as robust as I am hoping for. Here is the URL (kindly do not change the raw date):
https://docs.google.com/spreadsheets/d/17n3PYBrhlbD1RIgToohS3a1QbN5qhrQnREcMAnZdcbY/edit#gid=626607315
your shared sheet has restricted access. so here's a working formula based on rough sample data.
=QUERY(A:D, "SELECT * WHERE A = 'N502SY' and C >= date '"&text(EDATE(MAX(C:C),-6),"yyyy-mm-dd")&"' and C <= date '"&text(MAX(C:C),"yyyy-mm-dd")&"' ORDER BY C ASC")
-
You can try with FILTER and SORT too:
=SORT(FILTER(A1:D,A:A="N502SY",C:C>=EDATE(MAX(C:C),-6)),3,1)

Google Sheets formula that queries recurring data based on time interval/frequency

I'm trying to have a calendar display a series of activities based on their type, time and frequency for an easier visualization of data.
So far, I have managed to create a formula that correctly fetches the data that I have on a repository and displays it on the calendar. However, I'm not sure how I can have it account for entries that have a frequency (happening every x days).
For an easier understanding here are screenshots of both the table and the schedule
And here's the current formula I'm using to display the event/activity title in each day/hour at C12 for example:
=IFERROR(
INDEX(Repository!$K:$K,
MATCH(
C$10,
IF(
(Repository!$G:$G=$G$8)*
(Repository!$H:$H=$K$8)*
(Repository!$N:$N>=$B12)*
(Repository!$N:$N<$B12+TIME(2,0,0)),
Repository!$D:$D),
0)
),
"")
What I'm currently missing on the formula is a way to correctly account for the start/end date as well as frequency and understand if each day falls under the specified criteria. In case the frequency is 0 then I'd like to have it discard the end date at all (in case for some reason I end up forgetting to set the end date).
I have tried to work with the formula provided to account for the frequency but nothing that I tried seemed to work.
Minimal example
Entry on the table with a 2 days frequency:
Expected result on the schedule:
So basically, the formula on each cell should check for the start date, end date and frequency of the activity and identify if the specific date on the schedule falls under the specified timeframe.
In this minimal example, the activity starts on the 7th December and repeats every 2 days until the 14th of December.
Feel free to duplicate the spreadsheet here:
https://docs.google.com/spreadsheets/d/19h0v3XjDqa_DWSx-QBGBNwFGd550a_D3DVFovs5s2qo/edit?usp=sharing
I have tried to build the formula in multiple ways but I can't seem to make it count for the time frequency so that cells recognize this and display the activity in any other dates besides the initial one.
delete all your formulae and use this in C6:
=INDEX(IFNA(VLOOKUP(TEXT(C4:P4+B6:B14, "e-m-d-h-m")&G$2&K$2, SPLIT(FLATTEN(MAP(
Repository!D$4:D, Repository!O$4:O, Repository!P$4:P, Repository!N$4:N,
Repository!G$4:G, Repository!H$4:H, Repository!K$4:K, LAMBDA(d, o, p, n, g, h, k,
IF(DAYS(o, d)>=SEQUENCE(1, MAX(DAYS(o, d)), 0, p), TEXT(d+SEQUENCE(1,
MAX(DAYS(o, d)), 0, p)+IF(ISODD(HOUR(n)), (HOUR(n)*"1:00")-"1:00", HOUR(n)*"1:00"),
"e-m-d-h-m")&g&h&"×"&k, )))), "×"), 2, )))
then copy C6 and paste in C18, C30, etc.

How do I filter a list with date and time values by only extracting specific times each day?

I have a list of days and times in column A. Column B is a dollar value for each time value.
I want to get a specific time for each day and list the price in the next column. I have this right now:
The formula for column J is this:
=filter(A11:B,(mod(A11:A,1)*24)>=4.5,(mod(A11:A,1)*24)<=4.6)
This formula filters 4:30AM and the price associated with it.
Formula for column L is this:
=filter(A11:B,(mod(A11:A,1)*24)>=9.5,(mod(A11:A,1)*24)<=9.6)
Which filters only 9:30AM for each day and the price that goes with it.
As you can see, the dates stop matching when column J is 8/12/2021 and column L is 8/13/2021. This is because column L didn't have 9:30AM for 8/12/2021 so it skipped to 8/13/2021.
How can I make so that one of the columns skip a date if the other column doesn't match that time? I don't know if I explained that well but in the example above, column J should skip 8/12/2021 because column L didn't have 8/12/2021.
Another way of dealing with this issue is perhaps using UNIQUE and FILTER formulas but I'm not sure how that could be done. Any help would be greatly appreciated!
Here's a link to the spreadsheet: https://docs.google.com/spreadsheets/d/1TvP0_UsYJbLb5bscx2e4nTEnSkP5roBZpP8aIGdl414/edit?usp=sharing
I'm not 100% sure, but if you need to filter values so the time element is 09:30 and 04:30, then hide values where a date only occurs once (ie. no 09:30 value or no 04:30 value), you could use:
=arrayformula(filter(
filter(A11:B,(round(mod(A11:A,1)*24,2)=9.5)+(round(mod(A11:A,1)*24,2)=4.5)),
countif(int(filter(A11:A,(round(mod(A11:A,1)*24,2)=9.5)+(round(mod(A11:A,1)*24,2)=4.5))),int(filter(A11:A,(round(mod(A11:A,1)*24,2)=9.5)+(round(mod(A11:A,1)*24,2)=4.5))))>1)
)
Adjust >1 at the end to whatever logic you need (=2, <>1 etc).
You can also add sort() around everything if you need to.
Explanation:
It turns out that mod(A11,1)*24 doesn't round particularly well, so I suggest round(mod(A11:A,1)*24,2).
Therefore to filter the date/times for 9.30am and 4.30am, you can apply:
round(mod(A11:A,1)*24,2)=9.5
and
round(mod(A11:A,1)*24,2)=4.5
like this:
=arrayformula({filter(A11:B,(round(mod(A11:A,1)*24,2)=9.5)+(round(mod(A11:A,1)*24,2)=4.5))})
filter is usually AND but to get OR condition it's filter(A:B,(A=1)+(A=2))
This gets the dates only:
=arrayformula(int(filter(A11:A,(round(mod(A11:A,1)*24,2)=9.5)+(round(mod(A11:A,1)*24,2)=4.5))))
Then this counts how many times a date appears:
=arrayformula(countif(int(filter(A11:A,(round(mod(A11:A,1)*24,2)=9.5)+(round(mod(A11:A,1)*24,2)=4.5))),int(filter(A11:A,(round(mod(A11:A,1)*24,2)=9.5)+(round(mod(A11:A,1)*24,2)=4.5)))))
Combining the elements gets the solution.
I'll add a tab to your sheet.
You could filter each list on finding a match for each date (integer part of datetime) in the other list:
In J:
=filter(A11:B,(mod(A11:A,1)*24)>=4.5,(mod(A11:A,1)*24)<=4.6,isnumber(match(int(A11:A),int(filter(A11:A,(mod(A11:A,1)*24)>=9.5,(mod(A11:A,1)*24)<=9.6)),0)))
In L:
=filter(A11:B,(mod(A11:A,1)*24)>=9.5,(mod(A11:A,1)*24)<=9.6,isnumber(match(int(A11:A),int(filter(A11:A,(mod(A11:A,1)*24)>=4.5,(mod(A11:A,1)*24)<=4.6)),0)))
Note
Plz see Aresvik's answer for a possibly better approach to rounding, but note that 4:30 (3/16) actually has an exact representation as a binary decimal so rounding errors aren't an issue here.

Google Sheets Select X where (max(y)<=z)

my title is potentially not that enticing. But I am trying to create a semi-dynamic formula in order to find a "stock on hand" up to a particular date in time. There is a set number of locations ids 1-10, and two product types 3 & 4.
It is not guaranteed that each location will have a stock count at the date in question. I want to use query to find THE MOST RECENT stock count where location and product type and <= date
here is the basic formula
=QUERY(Sheet1!A160:E3530,"SELECT D WHERE ((B = "&$H$1&")) AND (E <= date '"&TEXT(MAX($M$3),"yyyy-mm-dd")&"') AND ((A = "&G2&"))", true)
But I need to figure out how to use MAX to find the most recent date within the date range specified.
Any help appreciated!
EDIT 23/06/2021
You will note this is a fraction of the data I have in my set (in the example sheet), so most numbers show as zero, but the formula
=MAXIFS($C$3:$C$6040,$A$3:$A$6040,I3,$B$3:$B$6040,$J$2,$E$3:$E$6040,(MAX(QUERY($A$3:$E$6040,"SELECT E WHERE (E <= date '"&TEXT($R$2,"yyyy-mm-dd")&"') AND ((A = "&I3&")) AND ((B = "&$J$2&"))", true))))
works on my full data. So this finds the most recent record of equipment type 3 or 4, up to the specified date and from a specified yard. Further filtering is done based on a change type of "converted, removed,dead,added,etc". What I want to do now is do a monthly or fortnightly line chart over time, eg the 14th and 29th of each month, or the 20th of each month and plot the the sum of each column J:Q. To start I hoped to use the date in U:U and populate the V:AC accordingly.
I have played with the onEvent script but I am struggling to make progess here

Formula for tracking Wins&Losses from a specific Year and Sports

This is the formula I'm currently trying to use, however it only results in 0's.
=ARRAY_CONSTRAIN(ARRAYFORMULA(SUM((Log!$G$3:$G$1000 = "W") * ((Log!$J$3:$J$1000 = B2 & Log!$B$3:$B$1000 = A2)))),1 ,1)
Log!$G$3:$G$1000 = Cells that are marked as W (for wins) and L (for losses).
Log!$J$3:$J$1000 & B2 = Which year the match was in.
Log!$B$3:$B$1000 & A2 = The sport.
If I remove the & Log!$B$3:$B$1000 = A2, the formula works just fine, but it's showing every result for every sport from every year, which isn't what I want.
I'm trying to get it to show only the wins from a specific sport for a specified year, but I can't get any formula to work.
Any idea?
Edit: I should have noted, this is for google's spreadsheets.
I would suggest using the filter function:
=FILTER(Log!A-Z,Log!G:G="W",Log!J:J=$B$2,Log!B:B=$A$2)
note I guessed at the first array for A-Z so you should modify to reflect the actual range your trying to pull in. Also there are always slight difference, so if it needs to be modified a bit, then please share a sheet with some dummy data

Resources