How to get days between two dates in google sheet - google-sheets

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.

Related

Google Sheets - Formula to reference next cell in same row

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.

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"

Get max change between rows, ignoring empty cells at end of list

I have a spreadsheet where I'm tracking my net worth over time. Once a month, I add in my account balances.
In one sheet, I have this structure:
Date
Year
Net Worth
Account1
Account2
Account3
Jan 31, 2021
2021
$320
$200
$140
-$20
Feb 28, 2021
2021
$340
$200
$150
-$10
Mar 31, 2021
2021
$410
$250
$200
-$40
Apr 30, 2021
May 31, 2021
...rest of months for the year
The formula in the Year column is =if(C3<>"", year(A3), "").
The formula in the Net worth column is =if(sum(D3:F3)<>0, sum(D3:F3), "").
The Problem:
I'd like to have a cell which lists the greatest 1 month change (so $410 - $340 = $70), without having to update the formula every month. (In an ideal world, I never need to touch it again, only ever having to enter account balances once a month.)
What I've got so far:
=if(
abs(min(ArrayFormula(C3:C400 - C2:C399)))=max(ArrayFormula(abs(C3:C400 - C2:C399))),
min(ArrayFormula(C3:C400 - C2:C399)),
max(ArrayFormula(C3:C400 - C2:C399))
)
However, this includes the change from $410 to "", which is coerced to $0. So instead of the expected $70, I'm instead getting $410.
How can I get the greatest 1 month change, but ignore the empty string values?
Easiest way to fix it is just to put in an if clause I think:
=ArrayFormula(max(if(C3:C400<>"",abs(C3:C400-C2:C399),)))
because Max will ignore the empty string generated by the If statement
or slightly shorter:
=ArrayFormula(max((C3:C400<>"")*abs(C3:C400-C2:C399)))
so that the change for any empty cells is set to zero.
These assume that C2 itself is not blank!

Transpose and repeat column

I know this might be a long shot but here it goes:
Let's assume I have this data:
A B
2014 1
2015 2
2016 3
2017 4
2018
Those columns are not related. But based on that I would like to create a table like this:
2014 2014 2014 2014 2015 2015 2015 2015 2016 2016 2016 2016
1 2 3 4 1 2 3 4 1 2 3 4
Or even better have each column repeated 5 times. What I want to achieve i that I will have data for each year and quarter, and then I would like to display each quarter separately and at the end of each year to have an average:
2014 2014 2014 2014 2014 2015 2015 2015 2015 2015 2016 2016 2016 2016 2016
1 2 3 4 avg 1 2 3 4 avg 1 2 3 4 avg
I've used TRANSPOSE(A2:B6) but I'm stuck on the repetition side of things, if it's even possible
Since I have data in a first column, perhaps something like this is easier to achieve:
A B C D
2014 2015
Label A 1 x x
Label A 2 x x
Label A 3
Label A 4
Label B 1
The labels in A column are taken using QUERY, just a list of, for example, people - can I repeat them? The Xs would then be a singular query to get right data for column A,B, and C
There is rept for repeating a string a given number of times. It can be abused for other data by way of join and split, if you can pick a suitable delimiter (some character that isn't going to be present in the data). I use | as a delimiter:
=split(join("", arrayformula(rept(A2:A6 & "|", 5))), "|")
This puts the content of A2:A6 in a row, repeating each entry 5 times.
Similar trick to have the content of B2:B6 repeated but in a loop: 1, 2, 3, 4, avg, 1, 2, 3, 4, avg ... :
=split(rept(join("|", B2:B6), 7), "|")
Here 7 is the number of times the loop should be repeated.

Resources