Split revenue by year with Google Sheets' QUERY function - google-sheets

I get monthly revenue data from the finance department that I have clean to input into a reporting format. Its monthly data that lists all revenue in a single column. I need to split out the revenue by years (2018, 2019, etc.).
I believe that I need to use a query function for this but if you have some other solution, then I'm open to that too.
The data looks like this:
Client Source Month Year Revenue
abc Google 1 2019 100
abc Google 1 2018 100
abc Facebook 1 2018 50
abc Facebook 2 2018 50
And I need it to look like this:
Client Source Month 2018 Revenue 2019 Revenue
abc Google 1 100 100
abc Facebook 1 50 0
abc Facebook 2 50 0
I'm familiar with query functions but I can't wrap my head around how to do this.
The pseudo code for this would be something like:
select Client,
Source,
Month,
Case when Year in 2019 then sum(Revenue) as 2019 Revenue else 0 end,
Case when Year in 2018 then sum(Revenue) as 2018 Revenue else 0 end
from Data
Group by Client, Source, Month
Please let me know if I need to provide any additional information. And I appreciate your help with this problem.

=QUERY(A1:E, "select A,B,C,sum(E) where A is not null group by A,B,C pivot D", 1)

Related

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.

select all columns based on a specific row value Google-Sheets

Hi everybody I am trying to query an already formatted google sheets, I am able to filter some of those data (I used =query(x,select * where ... )). The output I get is the following:
may
may
june
june
july
july
july
planned
name
1
0
1
1
2
3
1
Now I want to refer to all the numbers under may (or june or july) in order to do some operation. I can' t just select the value I want because I need to automate it.
How can I get all the columns containing a specific marker(in my case the name of the month)? If it is not possible can you suggest me a different way to do that ? (I am not very experienced with google sheets or excel)
Since query can't select rows, you'd transpose it first and then select the columns you want and then retranspose it back, if needed:
Input:
may
may
june
june
july
july
july
planned
name
1
0
1
1
2
3
1
Formula(select columns >0):
=QUERY(TRANSPOSE(A27:I28),"Select * where Col2>0")
Output:
planned name
may
1
june
1
june
1
july
2
july
3
july
1

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

Google sheets Query WHERE only returns first row

I am trying to query data from a sheet matching two conditions. However, when there is more than 1 row in the data matching my condition the query only returns the first result. How do I make sure it returns ALL rows matching the conditions?
I tried changing the single and double quotes, capital letters, changing the format of the data but nothing worked.
The query:
query(Raw!A1:J29041, "select B,C,D,E, sum(F) where B='"&sheet1!A2&"' and E='good source' and not C='2016' GROUP BY B,C,D,E")
Example of data:
Client Year Month Source Count
Client a 2019 July other source 1
Client a 2019 July good source 2
Client a 2019 July bad source 22
Client a 2019 July good source 63
Client a 2019 July another source 1
Client a 2019 July another source 8
Desired output for this data:
Client Year Month Source sum
Client a 2019 July other source 65
numbers shouldn't be enclosed with single quotes
try:
=QUERY(Raw!A1:J29041,
"select B,C,D,E,sum(F)
where B="&sheet1!A2&"
and E='good source'
and not C='2016'
group by B,C,D,E", 1)
or:
=QUERY(Raw!A1:J29041,
"select B,C,D,E,sum(F)
where B="&sheet1!A2&"
and E='good source'
and not C=2016
group by B,C,D,E", 1)

VLOOKUP in a FILTER-ed range while automatically adding new rows

I have an easy-to-append monthly purchase log:
month prod count
-----------------
jan water 10
jan bread 20
feb bread 2
feb water 1
And I want to get a friendlier summary table:
prod jan feb
-------------
water 10 1
bread 20 2
Any idea how I can get this raport with new months in log appearing automatically as new columns?
I managed to get the month heads with a =ArrayFormula(TRANSPOSE(UNIQUE(FILTER(log!A2:A, log!A2:A<>"")))) and I am ok with entering the prod column by hand but I only managed to have a formula per column for count. And that means I need to drag the formula with each new month added to the log...
Any ideas? Thanks!
Try this formula:
=QUERY(A:C,"select B, sum(C) where A <> '' group by B pivot A")
See more info here:
https://developers.google.com/chart/interactive/docs/querylanguage
Use number of months instead of names to get 1, 2, 3 from feb, jan ordered alphabetically

Resources