Google Sheets - Sequence Dates across a table of data? - google-sheets

I have been able to use Google Sheet's SEQUENCE formula to provide me with sequenced dates for Partner 1 but then the formula stops and doesn't move on to Partner 2.
I have tried nesting within an Google's ArrayFormula but still cannot get it to function properly.
I'd like to avoid having to do each partner manually then copying and pasting each partner below the other.
Formulas I've tried:
For creating partner repeats based on number of days
=ARRAYFORMULA(TRIM(TRANSPOSE(SPLIT(QUERY( REPT($L$3:$L$16&",",$Q$3:$Q$16),,2^100),","))))
For sequencing dates, but only does the first range
=ARRAYFORMULA(TO_DATE(SEQUENCE(Q3,1,O3)))
CURRENT DATA
| Partner| Start Date| End Date | Total Days|
|:-------|:---------:|:--------:|----------:|
|Partner1| 3/1/2021 | 3/8/2021| 7 |
|Partner2| 3/1/2021 | 3/9/2021| 8 |
WANTED FORMAT
Partner Date
Partner 1 3/1/2021
Partner 1 3/2/2021
Partner 1 3/3/2021
Partner 1 3/4/2021
Partner 1 3/5/2021
Partner 1 3/6/2021
Partner 1 3/7/2021
Partner 1 3/8/2021
Partner 2 3/1/2021
Partner 2 3/2/2021
Partner 2 3/3/2021
Partner 2 3/4/2021
Partner 2 3/5/2021
Partner 2 3/6/2021
Partner 2 3/7/2021
Partner 2 3/8/2021
Partner 2 3/9/2021

You can do it generally by doing a vlookup of sequence number in the cumulative sum of the days.
For partner:
=ArrayFormula(vlookup(sequence(sum(D2:D),1,0),{sumif(row(D2:D),"<"&row(D2:D),D2:D),A2:A},2,true))
For date:
=ArrayFormula(to_date(sequence(sum(D2:D),1,0)
-vlookup(sequence(sum(D2:D),1,0),sumif(row(D2:D),"<"&row(D2:D),D2:D),1,true)
+vlookup(sequence(sum(D2:D),1,0),{sumif(row(D2:D),"<"&row(D2:D),D2:D),B2:B},2,true)))

You can use the following formula
=INDEX({SPLIT(A2&"#"&SEQUENCE(C2-B2,1,B2),"#");
SPLIT(A3&"#"&SEQUENCE(C3-B3,1,B3),"#");
SPLIT(A4&"#"&SEQUENCE(C4-B4,1,B4),"#")})
If still having issues, please share more info.
(do adjust ranges and locale syntax to meet your needs)

Related

Google Sheets availability chart formula

I am putting an overtime sheet together that staff can show their availability for the Saturday on a table with name and date with a simple Y/N, I also have another table for the hours each person has accumulated.
Based on several staff members saying Y to their availability (we have two members of staff in) I would like two cells to display the name of staff that has the least number of hours to their name.
Column A is the name
Column B is the hours they have worked
Column C is the checkbox,
checked meaning they will work overtime.
The following formula will return the two willing to work overtime with the least hours.
=query(A:C,"select * where A is not null and C = TRUE order by B limit 2")

Google sheets compare 2 fields on a different sheet and return one based on criteria

I have 2 different Google Sheets. Master Sales & Projections. On Master Sales I have 2 columns, Expected & Billed which has data broken down by billing weeks.
I need Sheet 2 to grab the data from the cell that not 0 since we are trying to track total sales for the month (expected & actual) and then at the end of the month we would have the real billed numbers.
Potato example below
Sheet 1
A B
1 Expect Billed
2 $123 $145
3 $145 $155
4 $156 $0
5 $132 $0
What Sheet 2 should look like
A B
1 Week1 $145
2 Week2 $155
3 Week3 $156
4 Week4 $132
Assuming you will arrange for the week numbers, in B1 please try:
={query(Sheet1!A2:B5,"select B where B<>0",0);query(Sheet1!A2:B5,"select A where B=0",0)}

Filter to the latest month and then filter to the best score per person

I've got a Google Sheet which holds the results of a monthly competition. The format is
Name | Date | Score
--------------------------------
Alan Smith | 14/01/2016 | 500
Bob Dow | 14/01/2016 | 450
Bob Dow | 16/01/2016 | 470
Clare Allie| 16/01/2016 | 550
Declan Ham | 16/01/2016 | 350
Alan Smith | 10/02/2016 | 490
Bob Dow | 10/02/2016 | 425
Declan Ham | 12/02/2016 | 400
Declan Ham | 12/02/2016 | 390
Clare Allie| 12/02/2016 | 560
I want to do 2 things with this data
I want to create a new sheet which holds the latest 'best' results. For the data presented here that would be
Alan Smith | 10/02/2016 | 490
Bob Dow | 10/02/2016 | 425
Declan Ham | 12/02/2016 | 400
Clare Allie| 12/02/2016 | 560
i.e. The results from February with the 'best' score per person. Here Declan Ham's lower score of '390' was removed.
I want another sheet to hold the tournament ranking. People are ranked by their top 3 monthly scores. i.e. The best score for each person for each month is obtained and the top 3 scores are combined to give their place in the tournament.
So far I've attempted to use Google queries, vlookups, filters to get these new sheets. But, just focusing on 1), the best I've been able to achieve is
=FILTER(Results!$A:$B, MONTH(Results!$B:$B) = MONTH(MAX(Results!$B:$B)))
Which will get me the results from the latest month. But it does not remove duplicates entries by people.
Does anyone have a suggestion for how I can achieve these requirements? Feel like I'm treading water at the moment.
Rather than trying to remove duplicates, you need to identify the maximum score by each person; you can do that by grouping values by person, then aggregating using max(). Here's how that would look, for the month of February 2016:
=query(Results!A1:C,"select A,max(C) where todate(B) > date '2016-2-1' group by A")
Instead of using a fixed value for the start of the latest month, we can get the year and month using spreadsheet formulas, and concatenate our query with them:
=query(Results!A1:C,"select A,max(C) where todate(B) > date '"&year(max(Results!B2:B))&"-"&month(max(Results!B2:B))&"-1' group by A")
That addresses your first question.
Tournament ranking
Your second goal is too complex for a single spreadsheet formula, in my opinion. Here's a way to accomplish it with multiple formulas, though!
The X & Y axes are filled out by spreadsheet formulas. On the X axis (orange), we populate participants names using this in cell A3:
=unique(Results!A2:A)
The Y axis consists of dates (green). These are the start dates of each unique month that there are scores for, calculated using the following formula in cell D2. This results in strings, e.g. 2016-01-1, and that format is specifically required for the later formulas to work.
=TRANSPOSE(SORT(UNIQUE(ARRAYFORMULA(TEXT(Results!B2:B13,"YYYY-MM-1")))))
Here's the formula for cell D3, which will calculate the sum of the 3 highest scores recorded for the user whose name appears in A3, for the month appearing in D2. (Copy & Paste the formula across the full range of participants & months, and it will adjust.)
=sum(query(Results!$A$1:$C,"select C where A='"&$A2&"' and todate(B) >= date '"&B$1&"' and todate(B) < date '"&IF(ISBLANK(C$1),TEXT(TODAY()+1,"yyyy-mm-dd"),C$1)&"' order by C desc limit 3 label C ''"))
Key points about that formula:
The query range needs to used fixed values so it isn't transposed when copied to additional cells. However, it's still open-ended, to absorb additional rows of scores on the "Results" sheet.
Results!$A$1:$C
A WHERE clause is used to select rows from the Results sheet that are for the given participant (A='"&$A2&"') and fall within the month that heads the column (C$1).
...and todate(B) < date '"&IF(ISBLANK(C$1),TEXT(TODAY()+1,"yyyy-mm-dd"),C$1)&"'
The best 3 scores for the month are found by first sorting the above result descending, then limiting the result to 3 rows.
...order by C desc limit 3
Finally, the QUERY headers are suppressed by this little trick, so that we get a single number as the result:
...label C ''
Individual tournament totals appear in column C, with a range SUM across the row, e.g. for cell C3:
SUM(D3:3)
The corresponding ranking in column B is then:
RANK(C3,C$3:C)
Tidy
For simpler copy/paste, you can do some error checking in these formulas, so that they can be placed in the sheet before the corresponding data is - for example, at the start of your season. Using IF(ISBLANK(... or IFERROR(... can be very effective for this.
B3 & down:
=IFERROR(RANK(C3,C$3:C))
C3 & down:
=IF(ISBLANK(A3),"",sum(D3:3))
D3 & rest of field:
=IFERROR(sum(query(Results!$A$1:$C,"select C where A='"&$A3&"' and todate(B) >= date '"&D$2&"' and todate(B) < date '"&IF(ISBLANK(E$2),TEXT(TODAY()+1,"yyyy-mm-dd"),E$2)&"' order by C desc limit 3 label C ''")))
Alternatively for the first part of your question (the latest 'best' results) , in addition to the solution provided by Mogsdad, this should also work.. :-)
=ArrayFormula(iferror(vlookup(unique(A2:A), sort(A2:C, 2, 0, 3, 0), {1,3}, 0)))
EDIT: This formula sorts the table with dates (col B) descending and col C descending and then (ab)uses the fact that vlookup only returns the first match to return the first and last column.

Combining the select clause in query function with Indirect function. - Google Spreadsheets

So basically I need a dynamic select statement which changes references when dragged across rows or columns.
Example of what I need.
=sum(query('Sheet1'!$A$1:$F$621, Indirect("Select"&$F&"Where A='ABC' AND B="&"Sheet2!"&$A1)))/20
Sample Sheet 1 (Data Sheet)..--Since I am not allowed to use images till i reach rep 10 lol :)
Column 1 - Sales Sites (ABC, DEF, GHI.....)
Column 2 - Sales Roles (SM, ASM, SE.....)
Column 3 - Sales in Month Jan
Column 4 - Sales in Month Feb
Column 5 - Sales in Month Mar
Sample Sheet 2 (Desired Output)
Description (in pivot terms):
Site wise (filter)
Role wise (Rows)
Month wise (Columns - Sum of Jan, Feb etc)
Value (Sum of Jan/20)--To get day wise sales numbers
FYI:
I have tried using pivots, but google spreadsheets don't allow use of calculated fields in pivots in any manner (for the /20 in the formula), hence trying to achieve the same results by formula.
I know a table on the basis of the pivot table could help solve this problem, but to make it more efficient I am trying to avoid using 2 tables.
Many Thanks for your help in advance, please let me know if you need additional info to understand the scenario.

How to get the data for the next two weeks?

I've several straight-forward planners, like this:
| date | person | person 2 | description |
2013-03-01 peter pam painting
2013-03-18 john carl cleaning
2013-03-20 max anne washing
On a different sheet, I want to filter the 'events' for the next 2 weeks only. How can I achieve this? I tried several ways, but none of them are working.
With =ARRAYFORMULA(DAYS360(B2:B;NOW())) I can get a daynumber in a different column. 0 = today, 1 = yesterday, -1 tomorrow et cetera. In fact, I need to filter the days -1 to -14. Sometimes there are only 2 events, sometimes 5 in 2 weeks.
Edit: Some things I found
First, I filter the correct daynumbers with =filter(A2:A50;A2:A50>-14;A2:A50<0)
Then, I do a vlookup =vlookup(G32,A1:E49;5;false)
(where G32 is the filtercommand, A2:A50 the daynumbers, A1:E49 all the data)
This is a good opportunity for the QUERY command and Query Language.
I'm assuming your data is in 4 columns, A:D, in "sheet 1".
=query('sheet 1'!A:D,"select * where datediff( A, now()) < 14 and datediff( A, now()) > 0")

Resources