I have the following three columns as data:
I am using the formula =IF(COUNTIFS($A:$A;A2;$B:$B;B2;$C:$C;C2)=1;1;0) as my output in the Output column. Basically I am giving a non-unique row a 0 and a unique row a 1.
However as you can see I want to give the first occurency of a unique combination of ART, Date and ISIN an 1 and the rest a 0. Why is my currently used formula wrong?
I appreciate your answer!
That's because your formula currently will put 1 for all unique rows and 0 for all duplicate rows, irrespective of whether they appear for the first time or not.
You can get the behaviour you're looking for by playing around a bit with the range lockings. For instance, you could try this:
=IF(COUNTIFS($A$2:$A2;A2;$B$2:$B2;B2;$C$2:$C2;C2)=1;1;0)
On the first row, the above formula will count only within the first row, so the result is bound to be 1.
When it reaches the second row, it will check the first 2 rows and will find that it's the same as the first one, so will return 2 as count and give you 0.
Notice how I locked the ranges: The first reference is completely locked $A$2:$A2 while the second one has the row variable $A$2:$A2.
Related
So I have data consisting of the following:
there are multiple more rows.
Im trying to retrieve the last 5 values in a row, for further use.
I can do this with a simple INDEX(MATCH()) setup, however that doesn't ignore the blank cells, which I would like it to do. It does successfully detect the first nonblank cell and returns that, however when it's blank in the middle of the 5 most recent, it doesn't remove that.
something like this is what it does now:
however i want it to come back in this format:
and so on. A blank could occur at any position, and there may not always be 5 scores available to retrieve.
TIA
You could use the following array-formula (entered with ctrl+shift+enter in older Excel versions):
=INDEX(1:1,AGGREGATE(14,6,COLUMN(A:G)/(A1:G1<>""),{5,4,3,2,1})) copied down.
Aggregate creates an array of the column numbers divided by 1 or 0 (TRUE or FALSE). Divided by 0 results in an error and gets ignored. It then takes the 5th largest to the largest column number without error and returns that as an array on the indexed row.
Where 1:1 represents the first row and A:G represents the first to last column used.
If you would want it on row 2 and column A:Z you'd have to amend it like this:
=INDEX(2:2,AGGREGATE(14,6,COLUMN(A:Z)/(A2:Z2<>""),{5,4,3,2,1}))
Different approach - using the new Excel 365 formulas:
This will return the values of the last five non-empty cells of row 2
=LET(
data,FILTER(B2:H2,B2:H2<>""),
cntData,COUNT(data),
matrix,SEQUENCE(1,MIN(cntData,5),IF(cntData>5,cntData-4,1)),
INDEX(data,1,matrix)
)
data returns all values except empty cells using the FILTER- formula
cntData holds the number of cells
using SEQUENCE a matrix is build that will return the column-indices to be returned. In case less then 5 values are available, the matrix returns 1 to cntData.
finally this "index-matrix" is used to return the values from the filtered data
This could be enhanced, by storing the number of cells to be returned within a named cell - and referencing this name in the formula. By that you could easily alter the number without altering the formula.
I'm learning to use array formulas and have been successful doing simple things like adding 2 columns together in a third column. For example, I can put =arrayformula(B:B+C:C) in D1 and it adds B and C for each row.
But now I have a situation where I want to subtract two numbers in the same column. I want to take the value of that column in the current row and subtract the previous row's value from it. Without array formulas this is simple: in O7 I put =N7-N6 and cop that down so O8 gets =N8-N7, etc. But that requires copying down every time - can I do the same thing with an array formula?
Basically, can I do something like =arrayformula(B:B+(B-1):(B-1)) ?
Context: column N is a monthly account balance. I would like to calculate how much that balanced changed each month. So for row 7, =N7-N6 gives me that difference. But I'm changing the entire spreadsheet to array formulas so I can stop pasting all of the formulas and I'm stuck on this one since it's comparing the same column.
I'm trying to get everything into Row 1 so my values and calculations can start in Row 2. For example, here's one of my formulas in Row 1:
arrayformula(if(row(A:A)=1,"Total gross income",if(LEN(B:B),B:B+C:C,"")))
Unfortunately, in Column O (the one I asked about originally) if I do this:
=arrayformula(if(row(A:A)=1,"Amount saved this month",if(row(A:A)>1,if(LEN(N:N),N2:N-N:N,""))))
Or this:
=arrayformula(if(row(A:A)=1,"Amount saved this month",if(row(A:A)>1,if(LEN(N:N),offset(N:N,1,0)-N:N,""))))
Every row is off by 1 - the result that should go in Row 3 goes in Row 2, etc. And if I do this:
=arrayformula(if(row(A:A)=1,"Amount saved this month",if(row(A:A)>1,if(LEN(N:N),N:N-offset(N:N,-1,0),""))))
Then it gives me an error because the offset function is trying to evaluate something out of range (possibly it starts with N1 and tries to grab a value 1 row above N1?)
Any advice on how to handle that out-of-range error?
I think the error is because of offset range N:N which starts from N1 and you are trying to shift it -1 or one cell up, which brings the formula out of sheet.
Try this formula instead:
=arrayformula(
{"Amount saved this month";
if(LEN(N2:N),N2:N-offset(N2:N,-1,0),"")})
It uses {} to make an array. See more info:
https://support.google.com/docs/answer/6208276?hl=en
Bonus. There is no reason to check row number now.
I'm attempting to grab each instance of the largest value within a range and display the five adjacent columns of data associated with each instance.
Sample
I was able to grab the largest data using this:
=IFERROR(LARGE($A$3:$A$100,ROW(1:1)),"NONE")
Unfortunately, I'm unable to figure out how to grab the adjacent data associated with the next instance of the duplicate value.
Note:
The archive table is in ascending order because that is the only way I can think of to ease copying and pasting the latest data.
If you do not want to use a sorted order, you can simply use this array formula at H3 and then auto-fill it to M8:
=IFERROR(INDEX($A$3:$F$18,SMALL(IF($A$3:$A$18=MAX($A$3:$A$18),ROW($1:$16)),ROW(A1)),COLUMN(A1)),"NONE")
This is an array formula and must be confirmed with Ctrl+Shift+Enter!
If you still have any questions, just ask ;)
EDIT:
The core is IF($A$3:$A$18=MAX($A$3:$A$18),ROW($1:$16)) which returns an array of rows and False like {FALSE,2,FALSE,FALSE,5,FALSE.....}. Knowing that SMALL ignores FALSE, You get with SMALL(...,1) the first row with the max value. (this way SMALL(...,2) will output the second row .....).
Using ROW(A1) and COLUMN(A1) as non static ref, you get the k for our SMALL and the column for our INDEX :)
Step 1)
Take your large function and compare it to the max from your source range, if it is less than max display none, if otherwise have it display the max.
Step 2)
Since your data is sorted in ascending order find the position in the range of the first instance of your maximum value.
=MATCH(MAX($A$3:$A$18),$A$3:$A$18,0)
We will use this to return the corresponding values in the adjacent columns by substituting it into an index formula for each column to be returned
=INDEX(B$3:B$18,MATCH(MAX($A$3:$A$18),$A$3:$A$18,0))
Place the above in I3 and copy it to right
Step 3)
Since your Data is sorted in order it means the next row down in column A of the max value will be still max value or end of the list. There for match value need to be increased by 1 for each consecutive row and needs some error handling
So we can use our formula from row 3 and adjust it as follows:
=IFERROR(INDEX(B$3:B$18,MATCH(MAX($A$3:$A$18),$A$3:$A$18,0)+1),"NONE")
OR
=IF(H4="NONE","NONE",INDEX(B$3:B$18,MATCH(MAX($A$3:$A$18),$A$3:$A$18,0)+1)
then change the +1 to a +2 then +3, etc however since we don't know wow many times this process will complete we can use the row reference which you started with and change the formula as follows:
=IFERROR(INDEX(B$3:B$18,MATCH(MAX($A$3:$A$18),$A$3:$A$18,0)+(row()-3)),"NONE")
OR
=IF(H4="NONE","NONE",INDEX(B$3:B$18,MATCH(MAX($A$3:$A$18),$A$3:$A$18,0)+(ROW()-ROW($A$3))))
the -3 being the hardcoded value for your first row of data which could also be changed to -ROW(A3) where A3 is a cell in the first row of your new table.
ERROR CORRECTION
I was adding the row bump to the match portion inside the match formula. This was a mistake. adding the +1,+2 or whatever needs to be added to the results of the match formula but still within the index formula. I have updated the formulas above to reflect this.
I have a list of names and numbers
NAME | Number
Joe | 1
Jane | 0
Jack | 1
Jill | 0
John | 1
I'm trying to look up the numbers and find out the corresponding name
The formula I have is
{=index($A$2:$B$6, SMALL(IF($B$2:$B$6 = 1, ROW ($B$2:$B$6)), Row(1:1)), 1)}
As I understand the formula:
First Excel runs the index function. It runs the index function on the array A2 through B6.
For the row number in the index function, it uses the function SMALL(IF($B$2:$B$6 = 1, ROW ($B$2:$B$6)), Row(1:1). This examines an array, b2:b6, and if the element under consideration in B2:B6 is a 1, it returns the row number of b2:b6. In this case, it would return a 2.
At this point I'm kind of stuck. I'm guessing that the second ROW function returns first case of the 1 derived from the small function
Lastly, the index function finds the name located in column 1 for the index found.
Your understanding of this formula is pretty good. I assume that you are going to copy it down enough rows to get all the values reported? If so, here is what is happening:
INDEX needs to know what row to go retrieve. In order to do this, we are going to give it a row number.
In order to get a row number we need to know which items meet the condition. We use the IF conditional to report a row number if the condition is met (otherwise we get FALSE).
Since that will give us an array of row numbers, we then use the SMALL function to give us a single value. That satisfies the INDEX function which needs a single row to retrieve.
So which value do we choose from SMALL? Well, we just give it a sequence of 1-2-3-... by using ROW(1:1). When this is copied down, it will become ROW(2:2), ROW(3:3), etc. Each of these will return 1, 2, 3, respectively so we get the next entry. Note that SMALL skips FALSE so it works for the output of the IF call.
So the first call to ROW (inside the IF) is used to determine the row of the values in the array that match the condition.
The second call to ROW(1:1) is just used to get an incrementing sequence once the formula is copied down.
The final thing to note is that your formula will be off by one row on the answers because ROW($B$2:$B$6) will return the absolute row number of those rows and not one that is relative to the starting corner of the array of interest. In this case, you will need to subtract 1 to get it to work (since it starts in row 2). In the general case, use a formula like this which accounts for the offset of the array:
=INDEX($A$2:$A$6,SMALL(IF($B$2:$B$6=1,ROW($B$2:$B$6)-ROW($B$2)+1),ROW(1:1)))
That is an array formula like you have (enter with CTRL+SHIFT+ENTER). The corresponding ranges look like:
I need to count the number of unique items (here I have the names of organizations) in the excel-sheet...I used the following script but I cannot introduce multiple inputs to count all of them at once.
=SUMPRODUCT((A27:A128<>"")/COUNTIF(A27:A128,A27:A128&""))
I want to introduce, for instance, A27:A128, A145:A156 lists of cells to be checked and counted.
Does anyone know how I can count them? Is there another function to be called?
Very simple........use a "helper" column, say column D In D1 enter:
=A27 and copy down thru D102.
In D103 enter:
=A145 and copy down thru D114
Finally use:
=SUMPRODUCT((D1:D114<>"")/COUNTIF(D1:D114,D1:D114&""))
The formula you need looks like the following
=SUM( IF( MATCH(A27:A128,A:A,0)=ROW(A27:A128) , 1 , 0 ) ,
IF( MATCH(A145:A156,A:A,0)=ROW(A145:A156) , 1 , 0 ))
and works like this:
For every area you want to check you need the following construct:
IF( MATCH(A27:A128,A:A,0)=ROW(A27:A128) , 1 , 0 )
This tries to match every cell from A27 to A128 to the whole column A and checks, if the row where the value was found is equal to the current row. If this is the case, we found the first occurence, if it is a repeated occurence, the row will be smaller (because MATCH always returns the first row where the value was found). Now if we found a first occurence, IF returns 1, otherwise 0.
SUM just sums up every if (that means, if you have a third area and so on, just keep adding more IF-constructs and you're done), resulting in summing up a 1 for every first occurence of a value and a 0 for every follow-up - and you get your amount of unique values.
Attention: The whole formula is a matrix formula. After you put it in the cell, you must not end the editing with pressing ENTER but with STRG+SHIFT+ENTER simultaneously. This way excel surrounds the formula with {}-brackets that you cannot enter manually. It changes the way excel evaluates the formula and you might get an error if you try it as normal formula.
Also, as the values get checked against the whole column A the formula might or might not fail, if a certain value appears inside and outside of a checked area, depending on the ordering of the values.