Google Sheets - Formula to reference next cell in same row - google-sheets

I have two columns where I cam looking up a value in another sheet for date and value. The values are in rows and I want to display the results in columns.
How the source data looks
How I'm pulling it
I can't figure how to make the formula drag down where Column value changes, but the Row value stays the same. Meaning, AA1 would drag down to AB1, AC1, etc.
105 Weds Feb 1 at 9:00 AM
101 Weds Feb 1 at 12:00 PM
115 Weds Feb 1 at 4:05 PM
111 Weds Feb 1 at 9:40 PM
116 Thurs Feb 2 at 12:05 AM
97 Thurs Feb 2 at 1:20 PM
='Data'!B1 ='Data'!B3
='Data'!C1 ='Data'!C3
='Data'!D1 ='Data'!D3
I've tried using an array and it works for the displaying the next value in the Column, but not the next value in the Row like I want.
I've also tried some scripts I was able to lookup but wasn't successful.

Related

How to use Google Query to combine multiple rows into a single row with IF & SUM

We can get the following raw data from our project management software:
Month
Project
Billable
Time
Jan 2022
Project 1
Yes
100
Jan 2022
Project 1
No
10
Feb 2022
Project 1
Yes
80
Feb 2022
Project 1
No
30
Jan 2022
Project 2
Yes
60
Jan 2022
Project 2
No
5
Feb 2022
Project 2
Yes
90
Feb 2022
Project 2
No
15
I need to change this data to the following format:
Month
Project
Billable Time
Non-Billable Time
Total Time
Jan 2022
Project 1
100
10
110
Feb 2022
Project 1
80
30
110
Jan 2022
Project 2
60
5
65
Feb 2022
Project 2
90
15
105
Putting the raw data into a Google Sheet I thought this might be possible using Google Query. I started with this:
=QUERY(dataRange,"SELECT Month,Project,SUM(Time) GROUP BY Month, Project")
But I can't work out how to separate Billable & Non-Billable time & include this on a single row with the SUM of both times. Is this even possible using =QUERY?
If =QUERY can be used, what syntax should I use?
If =QUERY can't be used, what method should I use instead?
Use the QUERY pivot clause like this (assuming your source table is in A1:D9 of your sheet):
=query(query({A1:D9},"select Col1,Col2,sum(Col4) group by Col1,Col2 pivot Col3 order by Col2",1),"select Col1,Col2,Col4,Col3,Col3+Col4 label Col3 'Billable time',Col4 'Non-billable time',Col3+Col4 'Total time'",1)
You can also try:
={{A1:B1,C1&" "&D1,"Non- "&C1&" "&D1,"Total "&D1};INDEX(BYROW(UNIQUE(FILTER(A2:A&"|"&B2:B,A2:A<>"")),LAMBDA(ax,{SPLIT(ax,"|",0,0),SUMIFS(D:D,C:C,"Yes",A:A&"|"&B:B,ax),SUMIFS(D:D,C:C,"No",A:A&"|"&B:B,ax),SUMIFS(D:D,A:A&"|"&B:B,ax)})))}

google sheets query filter by datediff is this possible?

So i use the following formula:
query(OVERVIEW!$B$11:$W;"Select B,C,D,I,G,H,K where month(C)="&0+$D$11&"and W matches '"&IF($B$10=TRUE;"CREATE PO";"")&"' Order by "&$B$3&"")
and what it does it checks in which month you are looking and based on the forecast it will check a couple of months and return the result in the table.
So for this example, lets say I have 12 monthly tables
Jan Feb Mar Apr Mei Jun Jul Aug Sep Okt Nov Dec
I want data to be filled under each table + forecast of 3 months
So in Jan, I get Mar orders for example. this works as it is now but if go to let's say
Okt it should give me 3 months later data so in Jan next year only the formula I have does it for this year only and if I remove the year part I get both years Jan and that is not what I want. it should count furter so Dec 2021 + 3 months will be Marth 2022.
Any pointers?
I was thinking something with Datediff en EOMONTH() functions??
Example what needs to be
UPDATE: Link to file:https://docs.google.com/spreadsheets/d/1ti7TdF2mWEGxA1E4FIeNJ7sEEtYTgu4UQtMxYqS7ets/edit?usp=sharing
Update I have created a working example in the second tab with the
following formula:
=IFERROR(QUERY(C4:C22,"select * where C >= date '"&TEXT(DATEVALUE(EOMONTH("01-01-"&E1,D1-1)+1),"yyyy-mm-dd")&"'and C <= date '"&TEXT(DATEVALUE(EOMONTH("01-01-"&E1,D1)),"yyyy-mm-dd")&"'"))
i do not know if this is the best solution but it works XD
=IFERROR(QUERY(C4:C22,"select * where C >= date '"&TEXT(DATEVALUE(EOMONTH("01-01-"&E1,D1-1)+1),"yyyy-mm-dd")&"'and C <= date '"&TEXT(DATEVALUE(EOMONTH("01-01-"&E1,D1)),"yyyy-mm-dd")&"'"))
pasting the above code in each colum and change the month to the same month you need for example Feb is "01-02"

How to get days between two dates in google sheet

I have been trying to get the number of days between two dates in google-sheet but sometimes it gives an integer and sometimes it gives another date. How to get only the integer?
Shared public sheet (sheet name DS):
https://docs.google.com/spreadsheets/d/10NzbtJhQj4hQBnZXcmwise3bLBIAWrE0qwSus_bz7a0/edit#gid=517697699
Example
SN COMPANY AppliedDate DaysSince Today
-----------------------------------------------------------
2 McDonald Feb 17, 2021 54 1
3 Nielson Feb 17, 2021 Apr 20, 1900 2 **This should be number NOT date
4 Edelman Feb 17, 2021 111 3
5 Upstart Feb 19, 2021 Apr 18, 1900 1
6 Root Inc. Feb 19, 2021 Apr 18, 1900 2
Required
For the column DaysSince I would like to have only number. I want number between two dates but sometimes the same formula works sometimes does not work.
Is there any other methods to get number of days between two dates?
Go Format > Number > Number to format you entire column. Your problem is that your format is set as Automatic.

How to count entries based on criteria

I have this column where I put the date when I performed some action, along with a hyperlink in it (=hyperlink("link", "action date"). I want to count how many of these actions were performed in the current month.
I can convert it to the month number just fine by using =MONTH(cell), but when I try to use COUNTIF(), it always gives 0
Formula I'm using:
=COUNTIF(MONTH(B5:B), "=month(now())")
I noticed the countif formula works if I only reference a single cell on the first argument, so if there is a way to iterate over all cells checking against the month and then adding those 1's, that would work too, but I can't conceive that formula in my head.
Thanks for the help!
Sample data:
Client 1 11 Jul 18
Client 2 12 Dec 18
Client 3 15 Aug 18
Client 4 15 Jan 19
Client 5 17 Jan 19
Client 6 18 Jan 19
=ARRAYFORMULA(COUNTIF(MONTH(B5:B), "="&MONTH(TODAY())))

Google sheets query returning incorrect date

I have a got a query where I'm trying to pull in the next 14 days events and previous 14 days events
For some reason, I'm getting very dates added which are in the past or way into the future
=QUERY(Sheet1!A2:H200,"select A,B,G where dateDiff(now(), G) <14 and G is not null")
ABC 1 15 Feb 2019
ABC 1 1 Nov 2018
DFG 1 11 Nov 2018
ABC 1 2 Nov 2018
Next is the previous 14 days
=QUERY(Sheet1!A:G,"select A,B,G where dateDiff(now(), G) >14 and G is not null")
ABC 1 20 Oct 2018
ABC 1 20 Oct 2018
I'm doing something wrong with the query
https://docs.google.com/spreadsheets/d/1WI-FS0XFGi09d2wO005S3kOV_L2s9eR3ILxST6I1nVU/edit?usp=sharing
If you wanted to do it all using datediff, it would be
=query(A:C,"select A,B,C where datediff(C,now())<14 and datediff(C,now())>0")
for dates in next fortnight (fourteen nights or 2 weeks) and
=query(A:C,"select A,B,C where datediff(now(),C)<14 and datediff(now(),C)>0")
for previous fortnight.
You might want to put <= and >=, depending whether you want to include today's date and date 14 days before/after today.
When you use less than 14, Future dates are also included because datediff returns a negative number. So, add a another condition to exclude future dates like:
=QUERY(A:C,"select A,B,C where dateDiff(now(), C) <14 and C<now() and C is not null")

Resources