Trying to set up a formula where I can pull N counts based off multiple criteria including a date range. A typical Countif formula could work in theory:
=countifs(D2:D, J2, F2:F, J3, E2:E, J4, G2:G, J5, C2:C, ">="&TODAY()-7, C2:C, "<="&TODAY())
However, the problem I am facing is I want to be able to still pull the N count even if I leave one or more data validated cells the formula is pulling off of blank. In order to pull anything, you have to select one of the 4 data validated options. As you select more, the data gets more granular. Currently if I leave one cell blank, I then get a zero on the return. Need that not to happen
Any thoughts on how I could make this work?
I have done this with queries before, but I am not sure how to pull N count if use query. Happy to go that route as well if its easiest
use:
=COUNTA(IFNA(QUERY(C:G,
"select C
where 1=1 "&
IF(J2="",," and D = '"&J2&"'")&
IF(J3="",," and F = '"&J3&"'")&
IF(J4="",," and E = '"&J4&"'")&
IF(J5="",," and G = '"&J5&"'")&
" and C <= date '"&TEXT(TODAY(), "yyyy-mm-dd")&"'
and C >= date '"&TEXT(TODAY()-7, "yyyy-mm-dd")&"'", 0)))
Google Sheets. I want to get the next smaller value of the current value in COL A.
I've tried this...
=MAX( FILTER(INDIRECT("A" & ROW()-1 );MAX(A:A)) )
Looks good for the moment if the values in COL A are sorted.
The formula above is needed to pasted in each field.
"but", I want to use ARRAYFORMULA() ... I'm trying a long time (months) with breaks ...
That's one of my last tests.
=ArrayFormula(IF(ROW(G:G)=1;"Trip"; IF(ROW(G:G)<3;"0"; MAX( FILTER(INDIRECT("A" & ROW() );MAX(A:A)) ) ))
I've already tried VLOOKUP, too. But maybe I'm at the wrong way.
Unfortunately I didn't found a solution which match my case.
Does anybody can solve my issue? Or give me a hint to can solve this by my-self?
UPDATE Jan 26, 2021
Here we go... I've created a dummy sheet based on original values but cut not needed cols.
https://docs.google.com/spreadsheets/d/1yI0UEdZ3aKU03ElPchUuAPcmnAoMmCyXWhZBcu2Hv3g/edit#gid=0
Col A - is the "current value"
Col G+H - are some tries with ArrF
Col J - is working but not with ArrF - Shows the diff to the last value. Yes this can also be done without INDIRECT() and Co. But I want to try the basic logic.
Col K - show the last value.
Currently Col A is sorted. But if not the diff isn't working. I have added some values from above (grey marked) to simulate.
The goal should be to get the next smaller value of "current" COL A using ArrayFormula.
Use OFFSET
See the docs: OFFSET
=
{
"Last";
0;
ArrayFormula( OFFSET(A3:A, -1, 0) )
}
=
{
"Diff";
0;
ArrayFormula( A3:A100 - OFFSET(A3:A100, -1, 0) )
}
I changed the structure slightly so that it would be contained within arrays. That way you don't need the IF statements for the headers, for example.
I also did not use the whole column notation A:A partly because the array already has A1 and A2 covered. I tried A3:A but that didn't work for the diff column, because it always says it needs more rows. Probably because it needs to reference a row that is not on the same row, if that makes sense.
Refs
Arrays
OFFSET
UPDATE
Due to international settings you may need to have your functions written in this way:
=
{
"Last";
0;
ArrayFormula( OFFSET(A3:A; -1; 0) )
}
=
{
"Diff";
0;
ArrayFormula( A3:A100 - OFFSET(A3:A100; -1; 0) )
}
I'm sure this is probably a simple answer but I can't work out where I'm going wrong. I have a data table that I've copied to a new tab from (ForMaster!A511:G574). It brings in 7 columns data, the last 2 columns containing numerical values.
Sample Doc
https://docs.google.com/spreadsheets/d/1zcIHvSM1V_rVH8uiRE1ZhQHkptJLLlw9gnumSurZOps/edit?usp=sharing
I've been trying to set up a query that would look at columns F & G and remove rows where there is a zero in both columns. Ultimately, I want rows that have a $value in either to remain. This is a live doc, so if a row initially has a zero, I'd like it to be visible if a value is added at a future date.
I've tried using
=QUERY({ForMaster!A511:G574},"select * where Col6 >=0 or Col7 >=0"), but it doesn't eliminate any rows.
Please help.
The comparison should be only greater than 0 to eliminate rows with both zero values.
=QUERY({ForMaster!A511:G574},"select * where F>0 or G>0")
Sample Data:
try:
=QUERY(ForMaster!A511:G574; "where F+G <> 0"; 1)
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.
I've got the following Google spreadsheet:
item have ready need1 need2 need3
A 1 2 1
B 1 2 1 1
C 2 2
etc
I want to fill ready column as follows:
find the first column in need1, ..., needN range which has a non-empty value
if the value found is less or equals the value in have column, set ready column to something cheerful (e.g. yes)
if the value found is larger than the value in have column, don't do anything
So above input, when processed should look like this:
item have ready need1 need2 need3
A 1 2 1
B 1 2 1 1
C 2 yes 2
For the first step I found a suggested solution, which did not work for me:
=INDEX( SORT( FILTER( D10:H10 , LEN( D10:H10 ) ) ,
FILTER( COLUMN( D10:H10 ) , LEN( D10:H10 ) ) , 0 ) , 1 )
(it returns #REF!) Not sure what's wrong with it or how to proceed to the next step.
Thanks in advance!
If you know how many need columns you have, or even just how many columns are on the sheet, this is quite straightforward. If not and you need to look at the entire row, you might have to redesign a bit to avoid a circular reference from the cell with the formula being part of that row.
Your second two steps are fairly simple either way - you want one of two results based on a condition, so you're going to want to use =IF. Your condition is that the 'need' number is less than or equal to the 'have' number, and you want it to say 'yes' if that's true, and nothing if it isn't. So, that gives us:
=IF(need<=have, "Yes", "")
The examples below assume your table above starts from cell A1 in the top left, and that the last column in your sheet is Z
Next we need to find 'need' and 'have'. Finding 'have' is pretty easy - it's just the number in column B.
Finding 'need' is slightly more complicated. You've got the right idea using INDEX and FILTER, but your formula seems a little overcomplicated. Basically we can use FILTER to filter out the blank values, and INDEX to find the first one that is left. First, FILTER:
The range you want to filter from is everything in the same row from column D to column Z (or whatever the final column is), and the condition you want to filter for is that those same cells are not blank. For the formula you're typing into cell C2, that gives us:
=FILTER(D2:Z2, D2:Z2<>"")
Next, INDEX: If you give INDEX an array, a row number, and a column number, it will tell you what is at that the cell where that row and column meet. As we've filtered out the blanks, we just want whatever is left in the first column of our filtered array, which gives us:
=INDEX(FILTER(D2:Z2, D2:Z2<>""), 1, 1)
Or, as we only have one row in our array, and INDEX is pretty smart, simply:
=INDEX(FILTER(D2:Z2, D2:Z2<>""), 1)
So to bring it all together, our final formula for cell C2 is:
=IF(INDEX(FILTER(D2:Z2, D2:Z2<>""), 1)<=B2, "Yes", "")
Then just drag the formula down for as many rows as you need. If your sheet is or becomes wider, just change Z to whatever your last column is.
When you don't know the size of a range, use functions row, column, rows, columns.
Simple formula
Here's an example of what you are looking:
=if(INDEX(FILTER(OFFSET(D2,,,1,COLUMNS(1:1)-column(D2)+1),OFFSET(D2,,,1,COLUMNS(1:1)-column(D2)+1)<>""),1)<=B2,"yes","")
this part of formula:
OFFSET(D2,,,1,COLUMNS(1:1)-column(D2)+1)
returns the range starting from given cell (D2) to the end of Sheet (COLUMNS(1:1)-column(D2)+1)
ArrayFormula
I suggest using ArrayFormula, it'll expand automatically:
=ARRAYFORMULA(if(REGEXEXTRACT(SUBSTITUTE(trim(transpose(query(transpose(OFFSET(D2,,,COUNTA(A2:A),COLUMNS(1:1)-column(D2)+1)),,COLUMNS(OFFSET(D2,,,COUNTA(A2:A),COLUMNS(1:1)-column(D2)+1)))))," ",", "),"\d+")*1<=OFFSET(B2,,,COUNTA(A2:A)),"yes",""))
It assumes that 'Item' column has no blank values.
The solution from #Max Makhrov works, and has the advantage of using a single formula for the whole column.
However, it assumes that all of your columns at the right from your ready column (D) will be need_ columns.
The solution from #dmusgrave also works, provided you remove the extra "=" before INDEX:
=IF(INDEX(FILTER(D2:Z2,D2:Z2<>""),1)<=B2,"Yes","").
However, it makes the same assumption, and also limits at column Z.
Such assumptions seem reasonable, but if they are limiting you, here's how you can have any number of need_ columns starting right of your ready column:
=IF(INDEX(FILTER(INDIRECT( "D"&ROW()&":"&CHAR(67+COLUMNS(FILTER($1:$1,LEFT($1:$1, 4)="need")))&row() ), INDIRECT( "D"&ROW()&":"&CHAR(67+COLUMNS(FILTER($1:$1,LEFT($1:$1,4)="need")))&row() )<>""),1)<=B2,"Yes","")
The idea is simply to replace D2:Z2 (in #dmusgrave's solution) by :
INDIRECT( "D"&ROW()&":"&CHAR(67+COLUMNS(FILTER($1:$1,LEFT($1:$1, 4)="need")))&row() )
Explanation: You start from D at current row, and you go until the last need_ column on the same current row.
CHAR(68) is D, to which you add the number of columns titled need.*, minus one (hence the 67).
Using the same logic, you can easily make your formula more robust/generic, such as not having the need_ columns starting right form the ready column, etc.