Find Last Non-zero (+Non-blank) Row Meeting Criteria in Google Sheets - google-sheets

I am trying to get the last non-zero, non-blank value of a row within a column (Column F in my example image) wherein that row ALSO matches a Campaign name (Column D).
Most search results yield an Excel-specific variation of =LOOKUP(1,1/(L:L>0),L:L), but this doesn't work in Google Sheets.
I am trying to solve for Cell F23 = 2374.
I found and modified a formula which returns the last non-zero, non-blank value within a column reliably, but I don't know where to mix the additional filter (basically, D$2:D22 = D23) into the INDEX function.
Here is what I'm working with:
=if(
{{separate_formula_that_fetches_value_from_other_sheet}})=0,
INDEX((FILTER(D$2:F22,NOT(ISBLANK(D$2:F22)))), (ROWS(FILTER(D$2:F22,NOT(ISBLANK(D$2:F22))))),3)
)
Here is the example table:
Thank you for any help!

If you are trying to find inside RANGE B2:F22 which...
value in Column F is not empty and greater than 0, and
value in Column D matches D23,
try this, didn't test it, but it should work I think:
=LAMBDA(FILTER,
INDEX(FILTER,COUNTA(FILTER))
)(FILTER($F$2:$F$22,$F$2:$F$22>0,$D$2:$D$22=$D23))

Related

Google Sheets Query, 'where' condition not working?

I'm trying to separate specific rows of data into a new sheet, based on the text string in Column H / 8;
=query({attendees_list!A2:N2},"select Col1,Col2,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12,Col13,Col14 where Col8='Show1 - Adult (Earlybird Pricing)'",1)
The query is working, in that it returns columns 1-14 from the 'attendees_list' sheet, but it doesn't seem to be applying the "where" condition, as its returning all rows regardless of the Column H value, rather than returning the specified value; 'Show1 - Adult (Earlybird Pricing)')
Here is a document with the example of the issue
https://docs.google.com/spreadsheets/d/1LEISiYnFeOloA5FDmzA3B5fhXVY_YJiivxedR5qurpU/edit?usp=sharing
I've tried different string quote types (ie; ''&"") but I can't figure out the issue.
Any idea where I'm going wrong here?
the issue is in the range A2:N2 <- that's one row and then 3rd query argument set to 1 will treat that single row as a header row and always output it whatever you setup in 2nd query argument
try:
=QUERY({attendees_list!A2:N},
"select Col1,Col2,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12,Col13,Col14
where Col8 = 'Show1 - Adult (Earlybird Pricing)'", )

How can I find the closest matching value ABOVE the current cell, and return a different column in that same row?

Working in google sheets, I am trying to find the closest matching value ABOVE the current cell and return a different column from that same row.
Here is a visual of what I'm trying to achieve:
For any row where Column A=x, just return the value in Column B to Column "Results". If Column A does not equal x, I want to return the closest (in distance) Column B value where Column A=x above the current row. The first part (where Column A=x) is simple, but I'm having trouble with the second part, where Column A <> x. I've tried various iterations of index match, vlookup, but I keep ending up with either the first or last match, rather than the closest (in distance) above.
Thank you so much!
Try LOOKUP:
=ArrayFormula(LOOKUP(1,1/($A$1:A1="x"),$B$1:B1))
try:
=INDEX(IF(B:B="",, VLOOKUP(ROW(B:B), IF(ISNUMBER(1*B:B), {ROW(B:B), B:B}), 2, 1)))

Third Parameter in Array Formula to check for highest(max) occurence but only if the other conditions are true first

Ok, this is the updated linkI have multiple criteria to look through in my arrayformula(index(match())). The first two are simple as they reference the row the formula is calculating on. The last conditional I have is to find the highest occurrence in a given range, but ONLY if the other conditions are met...something like a filtered maxifs..any ideas?
Here is my code in column P =iferror(ArrayFormula(index($F:$F,match(1,("Fee Taken"=$C:$C)*(H12=$H:$H)(maxifs($M:$M,$H:$H,H2,$C:$C,"Fee Taken"),0))),""))
The result that I would like is to return from column F if the name matches that rows name, the transaction type is "Fee Taken" from column C, and THEN if those conditions are true I want it to find the max value from column M based on those two criterias and return the column F value for that max value row..
Ive attached some pictues to show my data.
The last part of the Match function where I have the Maxifs equaling to eachother is where I am confused; my thoughts were to see if the maxifs for the item in Column "M" can be used as a criteria..but I do not think so....I only want the highest occurence F:F if both conditions are met and it is the highest value for both those criteria in column M..
Please let me know if you need anymore info..Thanks![
Working formula will be:
=ArrayFormula(index($F:$F,match(1,--(M:M=(maxifs($M:$M,$H:$H,H2,$C:$C,"Fee Taken"))),0)))

In Google Sheets, I want to populate cells in Column A with certain conditions, based on the contents of column B

In this sheet,
https://docs.google.com/spreadsheets/d/1MR0n1FoutASbuwiNJS7FrcQhxHF6Bo03oVs9RZPo9g4/edit?usp=sharing
I am trying to have column B be populated with cell values equal to is today's date or tomorrow's date, by referencing column F.
Then, I am trying to have column A be populated with the contents of column E, based on if the column E's item is for today or tomorrow (Basically if the item's corresponding date shows up in B).
I've tried playing with index, lookup and filter but I cannot manage to get the formula right, and when using index and lookup there are many empty cells in between the dates.
I would appreciate any help.
I added a sheet ("Erik Help") with the following formula in A1:
=ArrayFormula(IFERROR(FILTER(E:F,(F:F=TODAY())+(F:F=TODAY()+1))))
That one formula returns all results you wanted to see.
Explanation:
The key part to understand is the condition that FILTER is using to filter in entries; and that is (...) + (...). The plus sign is the equivalent of OR in an array. So it's basically saying, "Filter in all results from E:F where (F:F = today) OR (F:F = tomorrow)." And if there is no match at all found for that OR condition, IFERROR will just return nothing (rather than an error).
Reference:
FILTER

Google Sheets - how to get the first and the last value?

Thank you for your time!
I am trying to make a trade journal in Google Spreadsheets.
What I want is the entry price and exit price of the trades,
Which are cell C10 and cell C11 in the screenshot image below.
I just manually typed the correct value - 960 and 2200.
Fortunately, the entry price for C10 is always what's in cell H2,
Because the first input will always be "Buy" in column F.
However I'm stuck finding the exit value.
I want it to find the last non-zero value of column H, only when column F contains "Sell".
What formula can I write?
enter image description here
You can do it with a combination of
INDEX
QUERY
COUNTA
Query for entries in column H where F is equal to "sell" and H is not 0.
From the retrieved subset of data, get the one with the last index (by counting the total amount of indices with COUNTA).
Sample formula:
=INDEX(
QUERY(F2:H, "select H where (F = 'sell' and H <> 0)"),
COUNTA(
QUERY(F2:H, "select H where (F = 'sell' and H <> 0)")
),
1
)
You can also do it without QUERY() (even though it is a really cool function).
=INDEX(H:H,MAX(IF((F:F="Sell")*H:H,ROW(F:F)),-1))
Find last row number where "Sell" appears in Column F and the corresponding value in Column H is non-zero. Since the row number monotonically increases, MAX() always gives us the last occurrence. If the row says "Buy" instead, or the value is 0, then IF() returns -1. We cannot use 0 because INDEX() evidently returns the whole range if we do that.
Use that row number as an index for column H to get the corresponding value. If no valid value was found, we get a #NUM error, which you can handle with IFERROR() if you'd like.
Note: we can't use a VLOOKUP() and approximate match because Action is unsorted.

Resources