Sorting by week in Google Analaytics Sheets add on - google-sheets

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))

Related

Pull data from big query to google sheet every Sunday at 11:59 pm for the last 21 days

It needs to pull data from BigQuery to Google Sheets every Sunday at 11:59 pm for the last 21 days.
Here's the code I wrote to find out Sunday.
SELECT
 EXTRACT(YEAR FROM date) AS year,
 week,
 name,
 parent_name,
 sum(total_sales) as total_revenue,
 title
 FROM partitioned_ts
WHERE
 id=14213
 and
 total_sales>0
 and
date BETWEEN DATE_SUB(CURRENT_DATE(), 
             INTERVAL 
             IF( EXTRACT(DAYOFWEEK FROM CURRENT_DATE()) = 1, 
                 6, 
                 EXTRACT(DAYOFWEEK FROM CURRENT_DATE()) - 1) 
             DAY) - INTERVAL 21 DAY AND DATE_SUB(CURRENT_DATE(), 
             INTERVAL 
             IF( EXTRACT(DAYOFWEEK FROM CURRENT_DATE()) = 1, 
                 6, 
                 EXTRACT(DAYOFWEEK FROM CURRENT_DATE()) - 1) 
             DAY)
GROUP BY name, parent_name, week, year, title
order by year DESC, week DESC, name
This query will process 85.31 GB when run. The old version of the query calculates the last 21 days from today
date BETWEEN DATE_SUB(CURRENT_DATE(), INTERVAL 21 DAY) AND CURRENT_DATE(
and this query processes only 1.6 GB when run. How should I write the query to process lower data?
The easiest way to filter out rows older than 21 days would be:
DATE_DIFF(CURRENT_DATE(), date, DAY) <= 21
If you need to reduce the scan size, the best approach is to partition the source table by date
https://cloud.google.com/bigquery/docs/querying-partitioned-tables#use_a_constant_filter_expression
The following code works:
date BETWEEN DATE_SUB((DATE_TRUNC(CURRENT_DATE(), WEEK(Saturday))), INTERVAL 21 DAY) AND (DATE_TRUNC(CURRENT_DATE(), WEEK(Saturday)))

Show value if months equals current month

I have a google sheet with monthly targets per product, and in another sheet I want to reference this and only show the target of the current month.
June 2022 July 2022 August 2022
Product 1 50 60 70
Product 2 20 40 60
The formula I tried is:
=IF(MONTH(A1)=MONTH(targets!$B$1:$D$1), targets!B2:D2, "")
Where A1 has =TODAY()
Use FILTER() function.
=FILTER(B2:D3,MONTH(B1:D1)=MONTH(F1))
You could also try
=index(B2:D3,0,match(G1,B1:D1))
But exact match might be safer
=index(B2:D3,0,match(eomonth(G1,-1)+1,B1:D1,0))
in case the required month is missing.

Google sheets formula to sumif within other sheets in the workbook, without writing out the sheet name, instead using reference/contents column?

I have a googlesheet (sheet 1) which looks like this:
contents contains a column with Months
May 2021
June 2021
July 2021
August 2021
September 2021
October 2021
November 2021
December 2021
January 2022
February 2022
March 2022
April 2022
May 2022
June 2022
Each month / cell in column A (sheet 1) all link to another sheet within the workbook containing the data for each month, all data has different rows, so to summarise each month, I want a formula like this:
=sumif(indirect(A4,&"!A:A"),"ProductA",(indirect(A&"!B:B")))
where A4 references January 2021, and this is linked to sheet January 2021, ProductA is in column A of each monthly breakdown (all sheets after sheet 1), and the number of these in column B.
I want to be able to drag this formula down, and have the sheet look for the sum of ProductA across all months, using Column A in sheet 1 to reference the sheet it should look in, i.e. the month.
Does this make any sense?
I can add more info, apologies for the waffle.
Sheet 2 for example contains Month1 data and looks like this:
Category (Ticket) Count Thread Time
prod1 5 22 8395:35:00
prod2 67 5411 644:24:00
prod3 544 55 18283:24:00
prod4 56 546546 97093:52:00
prod5 75 646 38238:11:00
Here is a formula that should work for you:
=arrayformula(sumif(indirect($A2&"!A:A"),C$1,(indirect($A2&"!B:B"))))
You can place this into cell C2, and then copy it down and across.
The issue with your formula was first that you had (indirect(A&"!B:B")), instead of (indirect(A2&"!B:B")).
Secondly, you need to make sure that there's no extra space after your values.
In the above image, you have an extra space after prod3, so when using the SUMIF and trying to match the value, it was not working. If something is resulting in 0 where it shouldn't be, make sure to check that first. I have found that prod4 and prod6 both have the same issue.

Google Sheets not calculating right?

can it be that Google Sheets is not calculating right?
=DAYS360(DATE(2016;12;31); date(2017;1;1))
is 1 and also this is 1 but is should be 2:
=DAYS360(DATE(2016;12;30); date(2017;1;1))
Whats wrong here?
I think it is because of the formula that is set to 360 days. It is said here that DAYS360 - Days between two dates on a 360-day year. So it means that you will only have a 30 days a month not including the date 31 in the months of (Jan, March, May, July, Aug, Oct and Dec).
For example, you use this =DAYS360(DATE(2016,10,25), date(2016,10,30)) so the expected output is 5 - which is correct
If you use =DAYS360(DATE(2016,10,25), date(2016,10,31)) the expected output is 6 - because you specify the date 31.
But, if you use =DAYS360(DATE(2016,10,25), date(2016,11,3)), the output is 8 not 9 - because it did not include the date 31.
I hope I explained it clearly.

How to compare percentage change in year by only months entered?

I'm working in Google Spreadsheets trying to compare two years of data for each month.
year jan feb mar apr may etc
2012 4 3 5 6 4 3
2013 2 4 5
I want to be able to compare the data I have so far because if I don't have enough data, then the comparison will not be accurate until all of the months are complete.
How do I compare 2013's jan,feb,march to 2012's jan,feb,march and have it dynamically adjust?
For instance, if I input april, have it compare jan-april of 2012 as well.
Please try:
=IF(ISBLANK(B3),"",SUM($B3:B3)/SUM($B2:B2)-1)
in B4 and copy across to suit.
Yes, in this case the formula works (or not!) the same in Excel and Google Docs.

Resources