Pivoting/Processing Data in Google Sheets - google-sheets

I am trying to pivot data that has column headers with Dates but have quantitative values in regards to hours worked.
The data currently looks like this:
Name Task January Hours Worked February Hours Worked March Hours Worked
John Doe Admin 10 10 10
I want the data to look like this:
Name Task Date Hours Worked
John Doe Admin January 10
John Doe Admin February 10
John Doe Admin March 10
Is there any, more simplistic way of recreating this? I know it's not as easy as just pivoting fields as the 'Date' and 'Hours Worked' would be new fields hypothetically speaking. I'm working in the Google Sheets environment, but also have access to Tableau Prep. Thank you for your help.

={A1:B1,"Hours Worked";ArrayFormula(split(flatten(A2&"❄️"&B2&"❄️"&C2:E2),"❄️"))}
demo

try:
=INDEX(QUERY(IFERROR(SPLIT(FLATTEN(A2:A&"×"&B2:B&"×"&
REGEXEXTRACT(C1:E1, "^.+? ")&"×"&C2:E), "×")), "where Col4 is not null"))

Related

How to Calculate Age from Year Only in Google Sheets

I have the year a car was purchased in column A. For example, 2015. I'm trying to calculate the age of the vehicle comparing the year provided in column A to TODAY() in an arrayformula, like this...
={"Vehicle Age";arrayformula(if(A2:A="",,(datedif(A2:A,today(),"Y"))))}
For some reason, it gives me the number 115 as the result for every cell where a year has been specified. Any idea why? I can't seem to find an answer on this anywhere on the internets.
Thanks for your help!
You are mixing apples and oranges here, so to speak.
Internally, Google Sheets sees all full dates as a number of days from an origin point of December 31, 1899. As such, the year 2015 on its own, in a comparison with a full date will be seen as two-thousand-fifteen days since December 31, 1899 (or July 7, 1905 — which was 115 some-odd years ago, as would be the case with any relatively recent year, because they'll all be interpreted in their raw form by Sheets as a cluster of days from late June to early July of 1905).
Instead, you want to compare the years only, which will mean extracting the year from TODAY(), since A2:A are already year-only numbers:
={"Vehicle Age";arrayformula(if(A2:A="",,year(TODAY())-A2:A))}
However, since any year's car models are actually released the year before, you may want to add a year to your formula:
={"Vehicle Age";arrayformula(if(A2:A="",,year((TODAY())-A2:A)+1))}
Of course, you could also have turned your A2:A years into real dates (e.g., January 1 of each year listed) and then used datedif as well:
={"Vehicle Age";arrayformula(if(A2:A="",,datedif(DATE(A2:A,1,1),today(),"Y")))}
... or with that extra year added ...
={"Vehicle Age";arrayformula(if(A2:A="",,datedif(DATE(A2:A,1,1),today(),"Y")+1))}
={"Vehicle Age";arrayformula(if(A2:A="",,datedif(DATE(A2:A,1,1),today(),"Y")))}
Not working

Select a "tax month" with a non standard month start/end

I have a Google Sheet with data like this:
Date
In
Out
July 13
£40
July 21
£60
etc.
I'd like to add another column "month" which specifies what month the entry was made in. Only problem is I can't use the standard MONTH() function because for accounting purposes, the tax month is 16th - 15th. So July 13 would be considered to be in the June/July tax month, while July 21 would be considered to be in the July/August tax month.
I'm assuming I will need to maintain a table of the specific cut off dates like so:
Month
Start
End
Jun/July
16th June
15th July
etc.
But I can't work out how to use this as a lookup table to achieve what I want. Any thoughts appreciated.
I think this should work if your date is in A1:
=IF(DAY(A1)>15,TEXT(A1,"MMMM")&"/"&TEXT(A1+20,"MMMM"),TEXT(A1-20,"MMMM")&"/"&TEXT(A1,"MMMM"))
If sort order is important (e.g. in a subsequent pivot table) I would use this:
=IF(DAY(A1)>15,TEXT(A1,"MM MMMM")&"/"&TEXT(A1+20,"MMMM"),TEXT(A1-20,"MM MMMM")&"/"&TEXT(A1,"MMMM"))
Another way to specify the sort order is maintaining a separate table with sort order column. It's a completely different approach.
use:
=ARRAYFORMULA(IF(A2:A="",,IF(DAY(A2:A)<16,
TEXT("1/"&MONTH(A2:A)-1, "mmmm")&"/"&TEXT("1/"&MONTH(A2:A), "mmmm"),
TEXT("1/"&MONTH(A2:A), "mmmm")&"/"&TEXT("1/"&MONTH(A2:A)+1, "mmmm"))))

Sorting by week in Google Analaytics Sheets add on

I just want to run a simple weekly traffic report with the Google Analytics Sheets add on. It does work fine, but I can't seem to figure out how to sort the weeks in chronological order with the jump from 2019 to 2020.
This is how it looks like
Order of the weeks
Does anybody know what Order I need to enter to have the order from week 38 - 53 and then continue with 1,2...?
Include the year as dimension and order by year and by week, like this:
year week
2019 38
2019 39
2019 40
...
2020 1
2020 2
2020 3
For multi year weekly analysis, it's better to just use the corresponding Mondays for any date for your grouping/summing/analysis than it is to use "Week Numbers"
Those mondays can be obtained by using this arrayformula, assuming your dates were in column A (A2:A)
=ARRAYFORMULA(IF(A2:A="",,FLOOR(A2:A+5,7)-5))

Is there a Google Sheets formula or query to get an array of months within a date range?

I have a start date and an end date, and DATEDIF easily gets me the number of months within there. I'd like to write out each month within that range, e.g. for a date range:
Mar 1, 2016 - Jul 31, 2018
...I want to iterate over the number of months in that range and return a row for each month in the range, starting from the start date:
Mar 2016
Apr 2016
May 2016
(the rest of 'em)
Apr 2018
May 2018
Jun 2018
This may be a better illustration of what I'm after. This table shows my source, a sheet of unique subscriptions, each having an ID, a rate, and start and end date:
The table I want to generate automatically would iterate through each unique subscription ID row, and then give me a row for each months' subscription payment, across the start-end dates for that subscription ID:
This second table I just want to make dynamic and dependent on what's in that first table, to save time.
I understand I have to just put in the time and figure out how to do it like everyone else has, but if you know if this is even possible just using Google Sheets' standard functions and queries, I'd be filled with a renewed sense of hope.
Thanks in advance for any patient pointers.
I was curious if it is possible with a formula.
Here's the result:
=query({TRANSPOSE(SPLIT(TEXTJOIN("",1,TRANSPOSE(ARRAYFORMULA(TEXT(ROW(INDIRECT("a1:a"&MAX(FILTER(DATEDIF(D2:D,E2:E,"M"),A2:A<>""))))*(TRANSPOSE(FILTER(DATEDIF(D2:D,E2:E,"M"),A2:A<>""))>=ROW(INDIRECT("a1:a"&MAX(FILTER(DATEDIF(D2:D,E2:E,"M"),A2:A<>""))))),"0"","";;")))),",")),
ARRAYFORMULA(TEXT(EOMONTH(
VLOOKUP(TRANSPOSE(SPLIT(JOIN("",REPT(ROW(INDIRECT("A1:A"&COUNTA(A2:A)))&",",FILTER(DATEDIF(D2:D,E2:E,"M"),A2:A<>""))),",")),FILTER({ROW(A2:A)-ROW(A2)+1,D2:D},A2:A<>""),2,),
TRANSPOSE(SPLIT(TEXTJOIN("",1,TRANSPOSE(TEXT(ROW(INDIRECT("a1:a"&MAX(FILTER(DATEDIF(D2:D,E2:E,"M"),A2:A<>""))))*(TRANSPOSE(FILTER(DATEDIF(D2:D,E2:E,"M"),A2:A<>""))>=ROW(INDIRECT("a1:a"&MAX(FILTER(DATEDIF(D2:D,E2:E,"M"),A2:A<>""))))),"0"","";;"))),","))-1
),"MMM YYY")),
ArrayFormula(VLOOKUP(TRANSPOSE(SPLIT(JOIN("",REPT(ROW(INDIRECT("A1:A"&COUNTA(A2:A)))&",",FILTER(DATEDIF(D2:D,E2:E,"M"),A2:A<>""))),",")),FILTER({ROW(A2:A)-ROW(A2)+1,A2:C},A2:A<>""),{2,4},))},"select Col1, Col3, Col2, Col4 label Col1 'Payment_Id', Col3 'Subscription_Id', Col2 'PaymentMonth', Col4 'PaymentAmount' format Col4 '$0.00'")
If you know js, It would be better to write a script using apps
script.

ArrayFormula Output Ordering

I am trying to take the output of the ArrayFormula in the top answer of this previous question, where the output is days of the week, and I want to output them in the proper order (Sunday, Monday, ..., Saturday).
Currently, when I use this formula I get the order Friday, Monday, Saturday, Sunday, Thursday, Tuesday, Wednesday. I have tried using the "order by" clause listing the days of the week in order order by("Sunday", "Monday", ..., "Saturday" without success.
My formula right now is =QUERY({H:H,H:H},"select Col1, count(Col2) where Col1 != '' group by Col1 label count(Col2) 'Number of Calls'",1).
A sanitized version of the data I am attempting to use is here. This data is over the course of one year. It has also been edited to include the two solutions I have so far for reference of future viewers.
Is it currently possible to do the ordering of the days within the Query? If not, what is the best way of going about getting the correct order.
I can't edit your sheet, but this is what I suggest. I don't understand why you have columns D-G, but I will assume you have a reason and work with what you have. First, change H2 to =weekday(F2) and copy it down to H66 (last row). This will return the number of the day of the week (Sunday=1, Monday=2...Saturday=7). Then in I2-I8 fill in the days of the week in the order Sunday through Saturday. In J2 put:
=COUNTIF($H$2:H,"=1")
for Sunday. In J3 put:
=COUNTIF($H$2:H,"=2")
for Monday. And so on through Saturday. That should do it.

Resources