I need help to fix a query formula. I am trying to pull specific columns with a criteria. Tried my very best to come up with a formula but I keep on having errors.
Here are the criteria needed for each column:
data headers = txn headers
Contact* = full_name
email* = email but will only shows a unique value
Product name* = relevant_item_name where it only contains "Not Your Average Membership" or "The Not So Average Membership"
Billing amt = total where the event is charge
Status = event either contains charge or rebill based on last order_date
Last billed* = order_date but only the last date of that email* (especially if it has multiple order dates)
Cycle = relevant_item_pricing_option when it contains monthly should show "monthly" or One-time payment should show "annual"
Charges* = the order_id usually shows orderidnumber-chargenumber so only the -x
This is the sample file:
https://docs.google.com/spreadsheets/d/1gJn6hHRRKxrvWhRu5WZ-OOXO_EBpMo3_gpFkPlckreQ/edit?usp=sharing
Is it possible to pull in one query? Do I just assume that it's possible but if not can you suggest the best approach on how I can show the required data.
use:
=SORTN(QUERY(txn!A2:AR,
"select D,S,AO,AB,AM,X
where AO = 'Not Your Average Membership'
and AM matches 'charge|rebill'
order by X desc", ), 9^9, 2, 2, 1)
stuff like S = UNIQUE(S) and X = MAX(X) are not supported in QUERY
| - or logic
9^9 - return all rows
2 - group by unique mode of sortn
2 - unique for 2nd column outputted by query
1 - in ascending order
added formula to your sheet here:
=SORTN(LAMBDA(z,FILTER(z,REGEXMATCH(INDEX(z,,3),"Average"),REGEXMATCH(INDEX(z,,5),"charge|rebill")))(SORT({txn!D2:D15,txn!S2:S15,txn!AO2:AO15,txn!AB2:AB15,txn!AM2:AM15,txn!X2:X15,IFS(REGEXMATCH(txn!AR2:AR15,"Monthly"),"Monthly",REGEXMATCH(txn!AR2:AR15,"One"),"Annual",TRUE,"N/A"),IFNA(--REGEXEXTRACT(txn!W2:W15&"","-(\d+)"),0)+1},txn!X2:X15,0)),2^99,2,2,1)
Related
I have two google sheets. One is more of a summary and the other one tracks all of the data. I need to get the price from the row on the 2nd page that is marked as entry, with a corresponding trade id to the first page, and then, if it was a long trade(Determined by the Long/Short(L/S) column on page 1, subtract the entry price from each exit price and then add those values together. If short trade it would be each entry price minus the exit entry price. Most trades will have 1 entry and 2 exits.
Basic example: Buy 3 contracts long at $10. Exit at $15 for 2 contracts and $20 for 1 contract.
So it will be (exit1 - entry) + (exit1 - entry) + (exit2 - entry). This
will give me the total points for each section of the trade. That data
then needs to get displayed on the overview tab
Example google sheet: https://docs.google.com/spreadsheets/d/1Y8QHrARyYjJKfOwq0g3waDfkVyWbWc2uSIzBiqsIal0/edit?usp=sharing
Edit: adjusted match to properly represent the outcome.
Try this one.
Formula:
=sum(query('Trades Taken'!A:D, "select D where A = "&A2&" and B = 'Exit'")) - (rows(filter('Trades Taken'!A:D, 'Trades Taken'!A:A = A2, 'Trades Taken'!B:B = "Exit")) * filter('Trades Taken'!D:D, 'Trades Taken'!A:A = A2, 'Trades Taken'!B:B = "Entry"))
I have simplified the formula so it would be easier to interpret.
Output:
I am trying to find a way to see which employees are not working between 2 dates.
Should I use vlookup, index & match, filter, query, or something else?
Sheet 1 contains employee details & start/end dates.
Sheet 2 accepts user input to select 2 dates, and it will automatically display a list of available employees who are not working.
Sheet 1 - Database/Log of all employees and days worked.
#
A
B
C
D
1
ID
Name
Start Date
End Date
2
12345
John
01/01/2021
01/08/2021
3
54321
Sarah
01/24/2021
01/29/2021
4
00731
James
02/05/2021
02/15/2021
5
00731
John
02/10/2021
02/30/2021
Sheet 2 (Row 1-2)- Manually enter in two dates.
#
A
B
1
Start Date (Manual input)
End Date (Manual input)
2
01/01/2021
01/30/2021
Sheet 2 (Row 3+)- List of all employees that are not working between the two dates entered in Sheet 2!A2:B2 (Expected Results)
#
A
B
3
ID
Name
4
00731
James
try:
=INDEX(SUBSTITUTE(UNIQUE(QUERY(""&SPLIT(FLATTEN(IF(SEQUENCE(1, MAX(D2:D-C2:C))<=D2:D-C2:C,
"♥"&A2:A&"♦"&B2:B&"♦"&C2:C+SEQUENCE(1, MAX(D2:D-C2:C), 0), )), "♦"),
"select Col1,Col2 where not Col3 matches '"&JOIN("|", "^$",
IF(SEQUENCE(1, G2-F2)<=G2-F2, F2+SEQUENCE(1, G2-F2, 0), ))&"'", 0)), "♥", ))
demo sheet
Assuming the name of your first sheet with the full data is actually Sheet1, place the following in Sheet2 cell A4:
=FILTER(Sheet1!A2:B,Sheet1!A2:A<>"",(Sheet1!C2:C>G2)+(Sheet1!D2:D<F2))
The combined either/or condition (Sheet1!C2:C>G2)+(Sheet1!D2:D<F2) in the FILTER means "either the start date is after the range date given, or the end date is before the range date given."
The other condition of Sheet1!A2:A<>"" just rules out blank rows in the original data set. It's not strictly necessary as far as the visual results are concerned; but it keeps null rows from being added to those results, which would allow you to enter data below the results in Col A and B of Sheet2 if you wanted, or to have fewer rows in Sheet2 than in Sheet1 without the formula adding more rows to accommodate null returns.
Your posted sample data is unclear. You have two different names for the same ID (i.e., 00731). And you have an "End Date" in D5 of February 30, 2021—which is not a valid date. In any case, it's unclear whether the same person/ID may turn up twice in the original data set. My formula above assumes you will not.
If your original data list may, in fact, contain duplicates, things get a bit trickier. In that case, use the following formula instead, in Sheet2 cell A4:
=UNIQUE(FILTER(A2:B,ISERROR(VLOOKUP(A2:A,FILTER(A2:A,((C2:C>=F2)*(C2:C<=G2))+((D2:D>=F2)*(D2:D<=G2))),1,FALSE))))
Here, the inner FILTER first forms a list of all people who are working during that range, and then the outer FILTER filters in a UNIQUE set of the people who are not on that inner list (i.e., trying to VLOOKUP them returns IS(an)ERROR).
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))}
I'm trying to refine my coding for a working spreadsheet by updating all the code to QUERY functions. One thing I am stuck on is where I average the last x rows matching specific conditions.
I was hoping that the following formula would work:
=QUERY(Ladder!A2:AE,"Select Avg(J) where F = '"&H$1&"' order by B desc limit "&$C$5)
My thought being that this would return the average of the last 3 rows - but I receive the
COL_IN_ORDER_MUST_BE_IN_SELECT error.
I only want the formula to return a single cell with the % average in it.
I realise that I could use the following code and then QUERY the Avg of that, but I want to be able to return % values for each different deck.
Here's a link to a cut down version of the spreadsheet:
Spreadsheet
Ladder: Where I enter the data
Ladder Filter: Where the data will filter based on query commands depending on criteria in the Ladder Stats tab
Ladder Stats: Where I can view all statistics and generate various statistical reports
It's all working at the moment, but as you can see it's very clunky and formula-heavy. I've worked most of it out except for the scenario you will find on the "Ladder Stats" tab - whereby B3="" and C5 != NULL. It is designed to give statistics for the last x games played by each of the decks.
you can either use a double query like this and format cell as %
=QUERY(QUERY(Ladder!A2:AE,
"select J
where F = '"&H$1&"'
order by B desc
limit "&$C$5, 0),
"select avg(Col1)
label avg(Col1)''", 0)
or you can use AVERAGE formula and click twice to get decimal position:
=AVERAGE(QUERY(Ladder!A2:AE,
"select J
where F = '"&H$1&"'
order by B desc
limit "&$C$5, 0))
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.