Google Sheets Query - Array formula in where clause and group by - google-sheets

I want to get sum of tax value, for each unique Tax Number, Bill nos for a set of Tax Numbers
Somehow my formula is failing. Let me know what mistake am I doing.
=Query(Bills!$A$2:$CM, "Select L,C, SUM(BC), SUM(AV), SUM(CE), SUM(CC), SUM(CD) where L Matches "&ArrayFormula("'"&textjoin("|",1,A2:A10)&" Group by L,C ",0))")")")

See if this helps
=Query(Bills!$A$2:$CM, "Select L,C, SUM(BC), SUM(AV), SUM(CE), SUM(CC), SUM(CD) where L Matches '"&textjoin("|",1,A2:A10)&"' Group by L,C",0)

Related

Unique number of dates for certain criteria

In the below screenshot I would like to get column E as my output. I need the unique number of dates where campaign/Ad group budget (col D) = campaign name (col B)
I tried using the following query "query(A2:E9,"select A, count(A) where E=B group by A")" and iterating it using Apps Script for loop. However, that did not work.
Is there any other way to find this output?
I think this formula will get you both the date and the count that are unique.
=unique(filter({A:A,E:E},B:B=D:D,B:B<>""))
You could then leverage an index function to get just on column. So this would give you just the count:
=Index(unique(filter({A:A,E:E},B:B=D:D,B:B<>"")),,2)
while this would get you the date
=Index(unique(filter({A:A,E:E},B:B=D:D,B:B<>"")),,1)
try:
=QUERY(A2:E9, "select A,count(A) where D=B group by A")

Google sheets question - filter sum equation

I have a list of email addresses in one sheet (first column).
I have a list of transactions in another sheet with emails and sale amounts.
I am looking for a formula that adds up all the transaction $ sales for any transactions made by the people (emails) in the first sheet.
Any help would be much appreciated!
Your sample data is very limited (only one row matching one person, in fact). But the following formula should work for you. Place it in a new sheet, in cell A1:
=ArrayFormula(IFERROR({"Name","Total"; QUERY(FILTER(Transactions!A2:D,NOT(ISERROR(VLOOKUP(Transactions!A2:A,Tags!A:A,1,FALSE)))),"Select Col2, SUM(Col4) GROUP BY Col2 ORDER BY Col2 LABEL SUM(Col4) '' ")},"No Data"))
This one formula will produce the headers (which you can change within the formula itself as desired) and all results.
FILTER filters in only 'Transactions' data (names through amounts) where the emails are found in the 'Tags' sheet.
Then QUERY returns the name and totals for each match in alphabetical order by name.
If there are no matches, "No Data" will show instead.
If I understood your question correctly!
Try this on the sheet, where you only have emails and wanted to get sum of sales amount
=sumifs(range_whichHasTransaction , range_of_Email_inThat_TransactionsTable , Cell_Reference_ofEmail_forWhich_you_want_sum_the_Transaction_Amount)
it will Look something like this:-
sumifs(TransactionSheet!B:B,TransactionSheet!A:A,Emails!A2)
Reference
SUMIFS

Google Sheets query function needing to provide 0 value for no value found

The query function looks at a separate sheet with orders entered by a dealer. In some months the dealer may not have a order. The B:B column in current sheet is all the dealers in Ascending order. Then I have separate columns for by month view with 3 columns per month. Number of contracts, amount then average. My query calculates correctly, but if a dealer doesn't have a contract then it skips. So my list is out of order. I'm needing it to place a 0 if no value found. I have 2 versions of the query.
J = amount, H = Dealer name, A = Date, the B = is the dealer list in current sheet.
This query populates but out of order due to skipping NUll or NA.
=QUERY('2021ContractsData'!A:V,
"Select COUNT(J),SUM(J),AVG(J)
WHERE MONTH(A)+1=1
Group By H LABEL COUNT(J) 'Contracts',SUM(J) 'Amount',AVG(J) 'Average'")
This query populates nothing, it shows the Header names but no values in rows.
=QUERY('2021ContractsData'!A:V,
"Select COUNT(J),SUM(J),AVG(J)
WHERE MONTH(A)+1=1
AND H='"&B2:B&"'
Group By H LABEL COUNT(J) 'Contracts',SUM(J) 'Amount',AVG(J) 'Average'")
Google Sheet View
try in C2:
={"Contracts", "Amount", "Average";
INDEX(IFNA(VLOOKUP(B3:B, QUERY('2021ContractsData'!A:V,
"select H,count(J),sum(J),avg(J)
where month(A)+1=1
group by H"), {2,3,4}, 0), 0))}

Sum column only of rows that match a condition (of another column)

I have a spreadsheet in Google with the following data:
**Status Amount**
Under Review $120.00
Delivered $50.00
Paid $320.00
Paid $110.00
Under Review $200.00
I want to sum all the column Amount, only but of only of those rows that has a Status on 'Delivered' or 'Paid'
With my example, the SUM should return $480.00.
I was trying with this formula, but it isn't working
=SUMIF(Column Amount,Status={"Delivered","Paid"},Column Amount)
Any ideas? Thanks a lot!
You can also use the following formula:
=SUM(QUERY(A2:B,"select sum(B) where A='Paid' or A='Delivered' group by A"))
One of your columns is incorrect, and you need to use the arrayformula function. Documentation here
=SUM(ARRAYFORMULA(SUMIF([status_column],{"Delivered","Paid"},[amount_column])))

How to join tables using Query or Vlookup

I have 2 sheets
people sheet has
[company first_name last_name full_name address_line1 address_city address_state address_zip address_country telephone email order_id order_date order_time processor order_type order_currency commission campaign_id]
sales sheet has
[DATE PROSPECT NAME EMAIL ADDRESS CONTACT METHOD PRODUCT RESULT NOTES ]
How do I make the report to generate when people.email = sales.EMAIL ADDRESS and display the records only if they match (Not all of sales sheet)
Report fields are
full_name
EMAIL ADDRESS
PRODUCT
commission
Sample File
Please try to use basic formula for joining sheets + query to skip some rows.
Basic formula:
=FILTER({Sales!B14:B,Sales!C14:C,Sales!E14:E, vlookup(Sales!E14:E,{People!B2:B,People!D2:D},2,), Sales!F14:F},Sales!A14:A<>"")
The formula you need:
=QUERY(FILTER({Sales!B14:B,Sales!C14:C,Sales!E14:E, IFERROR(vlookup(Sales!E14:E,{People!B2:B,People!D2:D},2,), "do not show"), Sales!F14:F},Sales!A14:A<>""),"select * where Col4 <> 'do not show'")
How it works
It uses iferror(expression, "do not show") to replace #N/A error with the text "do not show".
Then it uses query to hide rows with value "do not show":
"select * where Col4 <> 'do not show'"
Basic formula and the question is here
Notes about usage:
Sales!B14:B,Sales!C14:C,Sales!E14:E are some columns you need to select first
IFERROR(vlookup(Sales!E14:E,{People!B2:B,People!D2:D},2,) will return column from "People", it is column People!D2:D. Please note that columns Sales!E14:E and People!B2:B are both containing a key, in the sample it is e-mail list.
Sales!F14:F is a column to return next.
filter condition Sales!A14:A<>"" is to skip empty rows from original sheet. You may also add other conditions into a filter.
query part will shorten the report and skip values where keys (emails) do not match. You may add other conditions into a query.
Note. Query language in Google Sheets does not have joins, and provided solution is a workaround. It shows how to make a join with a help of vlookup function in Sheets.
The provided formula gathers rows from sheet "Sales" and makes vlookup to sheet "People". You also may want to make vice-versa report: collect data from "People" and 'vlookup` data from "Sales".
"Vice-versa" report:
=QUERY(FILTER({vlookup(People!B2:B ,{Sales!E14:E, Sales!B14:B, Sales!C14:C, Sales!E14:E},{2, 3, 4},), People!B2:B, IFERROR(vlookup(People!B2:B ,{Sales!E14:E, Sales!F14:F},2,),100500)},People!A2:A<>""),"select * where Col5 <> 100500")
note! In this formula used numeric value 100500 to skip values because query works with the single data type (number or text).
Please comment here if you have any questions about how it works.

Resources