I have a excel formula as below,
COUNTIFS($A$8:$A$14,$A8,$B$8:$B$14,$B8)
Here I want the criteria range to be calculated with a simple logic.
Instead of $A$14 I want this value to be calculated A$8+4 i.e. $A$14
In other words, it should get the current row and add 4 to be the criteria range for COUNTIFS
How can this be done is excel within the COUNTIFS formula?
Cheers
You could use =OFFSET(Cell Reference, Rows, Columns) within your formula to achieve this, for example:
=COUNTIFS($A$8:OFFSET($A$8,6,0),$A8, etc...)
Lets assume that the size of your range to be returned is stored in the cell D1.
=COUNTIFS($A$8:INDEX(A:A,ROW($A$8)+D1),$A8,$B$8:INDEX(B:B,ROW($B$8)+D1),$B8)
If you want the range to be defined as a certain number of rows after the current row as stated in your question, then still assuming the number of rows to be added is in D1, you would use the following:
=COUNTIFS($A$8:INDEX(A:A,ROW()+D1),$A8,$B$8:INDEX(B:B,ROW()+D1),$B8)
Expanding on Oliver's answer. The full format of OFFSET allows you to specify a whole range, not just one cell. OFFSET(Reference, Row Offset, Col Offset, Height, Width) so you could do:
OFFSET(A8,0,0,4,1)
This specifies the range A8:A11. In the COUNTIF
=COUNTIF(OFFSET(A8,0,0,4,1),A8,...)
Locking cells with $ works the same way within OFFSET if needed.
Try this:
=COUNTIFS(INDIRECT("$A$8:$A$" & 8+6),$A8,INDIRECT("$B$8:$B$" & 8+6),$B8)
Related
I am wondering, if there is a general way to express, that only visible rows of a formula should be taken into account.
If I have for example a formula sumif($E5:$E100; "ABC"; $F5:F100) it would be very helpful, if there would be a way to express, that the given ranges should only take visible cells into account. I could imagine that a kind of prefix can be specified to a range construct like % or that like. For example the formula then would look like sumif(%$E5:%$E100; "ABC"; %F5:%F100) to make clear, that in the given ranges only visible rows should be taken into account.
Same would then for example be for sum(%A1:%A100) which would mean, that in the range between A1 and A100 only visible cells should be taken to sum up the cells.
The point is, that this construct could be taken inside any kind of formula, no matter what it is.
Thanks in advance
Georg
Generically to sum sumrange based on a match in criteriarange.....but only for visible rows you can use this formula: =SUMPRODUCT((criteriarange=criteria)+0,SUBTOTAL(109,OFFSET(sumrange,ROW(sumrange)-MIN(ROW(sumrange)),0,1,1))) The first part (criteriarange=criteria)+0 just checks the criteria for each row and returns 1 for a match or 0 OFFSET returns an "array of ranges" with each range in this case being a single cell from the sum range. SUBTOTAL can process that and with the sum function (109) gives the "sum" (i.e. the value) of each cell, only when visible. – SUMPRODUCT then multiplies the two ranges and sums the result, effectively giving you the sum of visible rows where the criteria matches
Try This
=SUMPRODUCT(($E$5:$E$100="ABC")+0,SUBTOTAL(109,OFFSET($F$5:$F$100,ROW($F$5:$F$100)-MIN(ROW($F$5:$F$100)),0,1,1)))
I'm working on a spreadsheet that does some pretty bizarre calculations... The long and the short of it is that I need to search the values in the 4 folowing ranges.
C5:C293, E5:E293, G5:G293 & I5:I293. The issue is that those ranges can change but will stay consistent across the columns. So For example instead of 5:293 it might change to 5:290. Is there an easy way to say "Look at the cells that are rows X:Y and are in columns A, B, C or D?"
google-spreadsheets
ARRAYFORMULA: Commas , arrange the array horizontally and semi colons; arrange the array vertically( stacking on top of each other)
=ARRAYFORMULA ({C5:C293,E5:E293,G5:G293,I5:I293})
QUERY: If there's a pattern in the columns, This will isolate the array:
=QUERY(TRANSPOSE(C5:I293),"Select * skipping 2",0)
In Excel, use the INDIRECT() function.
So, have a Start cell in A1, and an End cell in A2. Then your formulas to sum a range would reference the ranges for C column as:
=SUM(INDIRECT("C"&A1&":C"&B1))
And D column as:
=SUM(INDIRECT("D"&A1&":D"&B1))
Use range names rather than Indirect() or Offset() functions in the worksheet.
Create one range that covers the desired rows in the first column, e.g. "red" in the example, then create additional range names that offset the required columns from that range name.
How you construct your initial range is totally up to the circumstances, but the range names with Offset() will be super fast to deliver a result, whereas Indirect() and Offset() in worksheet cells can cause significant speed issues.
Use offset function, if you are in google-spreadsheets, use it dinamically:
=offset(C5,,,counta(C5:C),1)
will reproduce the range of a proper length.
The question is slightly confusing, so I will do my best to elaborate. I have a series of cells in a row with all of the cells in the row with a value of 0 and one cell having a value of 1. I want to use the COUNT function to count all of the cells to the right of the cell that contains the value of 1, including that cell. I would then use this number of counted cells in another equation. Does anyone have any suggestions on how to do this? I have tried using a lookup function inside of the count function, but it has not worked. This is my closest guess:
=COUNT(Lookup(1,A1:J1):J1)
This results in an error. Do I need to use VBA to make this work or should I be able to write an equation? I appreciate the help, or if there are any other strategies that I can use to attain the result I am looking for.
Edit: I am adding in some sample data and expected results. I am trying to count all of the cells to the right of the "1" including the cell containing the "1". So in this example, I would expect the formula to return "13" as there are 12 cells to the right of the "1"
You can use OFFSET() and MATCH():
That last "50" is a bit of a guess since I'm not sure how far to the right you want to count...
...and re-reading your question it's not clear if you only want to count values of 1 or if you also need to count other values as long as they're to the right of the first 1.
With data in A1 through J1, consider:
=10-MATCH(1,A1:J1,0)+1
In this case. 4 is the number of cells from G1 through J1, inclusive.
Assuming your range of 0 and 1 values is in row 2, starting from column B, use this formula in B3 and copy it across for as far as you need:
=IFERROR(COUNT($B2:B2)+1-MATCH(1,$B2:B2,0),0)
You could also use a formula of
=IF(A3>0,1+A3,IF(B2=1,1,0))
but that could cause issues if you have something in cell A3 itself.
You can use this formula:
=COUNTA(INDEX($A$1:$J$1,1,MATCH(1,$A$1:$J$1,0)):INDEX($A$1:$J$1,1,10))
The benefit to use this is it is not a volatile function, and it will also work for 1 appears in the last column.
You can use "COUNTIF" formula to count number of occurrences of specific number in a range of cells.
To count no of occurrences in a row.
=COUNTIF(1:1,1)
If it is in a column then
=COUNTIF(A:A,1)
Hope you are looking for a countif function.
COUNTIF(A1:A10, 1)
The above function counts the cell that has value 1 within the range A1:A10
How can I find the minimum value in columns B:C in the table below if the volume is <= 10.
The expected result is in yellow.
Regards,
Elio Fernandes
Either:
=AGGREGATE(15,6,C2:C9/(A2:B9<=10),1)
or, array formula**:
=MIN(IF(A2:B9<=10,C2:C9))
If there may be blank cells in B2:C9:
=AGGREGATE(15,6,1/(1/C2:C9)/(A2:B9<=10),1)
or:
=MIN(IF(A2:B9<=10,IF(ISNUMBER(C2:C9),C2:C9)))
Regards
You can use this formula to get the minimum value (Which according to me should be 20 in your data set)
=MIN(1/AGGREGATE(14,6,1/((A2:A9<=10)*B2:B9),1),1/AGGREGATE(14,6,1/((A2:A9<=10)*C2:C9),1))
for each additional column(say D) you will have to add the formula 1/AGGREGATE(14,6,1/((A2:A9<=10)*D2:D9),1) inside the MIN() formula.
Looking for a better way to do this.
EDIT:
Alternatively you could add a new row below your data. for each column you add the below formula to get the min for that column
=1/AGGREGATE(14,6,1/(($A$2:$A$9<=10)*B2:B9),1)
Now you can drag this formula to as many columns you want. Take the MIN() of this row to get the overall minimum.
In Excel, the Offset function returns a reference to a range that is offset a number of rows and columns from another range or cell.
can someone please tell me what that means?
for example in this formula:
=OFFSET($B$4,ROW()-ROW($F$4),0,1,1)
what is it doing?
The purpose of OFFSET(BASE, ROW-OFFSET, COLUMN-OFFSET, NUM-ROWS, NUM-COLUMNS) is to select the content of cells that are NUM-ROWS rows and NUM-COLUMS distant from the base cell. If the selected cells are just one, then the content of that cell will be used as result, otherwise the result will be an array that can be passed to functions as SUM.
In your example, the function is simply selecting the content of the cell B4.
That example formula is odd, because it references a cell to get the row then takes that away from the current row - this bit ROW()-ROW($F$4, which might as well be row()-4, but there you go.
Offset, works like this
A cell location to start at, how many rows away from this, cols away from the this, optional size(rows), optional size(cols).