Flag Non-Unique Rows (After the First Instance) - google-sheets

I have a Google Sheets spreadsheet where I am needing to create an array formula that will determine uniqueness and flag non-unique rows. I need it to flag non-unique rows but only the second & subsequent duplicates (the first duplicate will not be flagged and should say "Unique"). I have this formula but it includes the first duplicate.
={"Unique";
ArrayFormula(
IFS(
$C$2:$C="","",
$C$2:$C<>"", IF(COUNTIF($A$2:$A,$A$2:$A)>1,"Not Unique","Unique")
)
)
}
How can I modify this formula to not flag the first instance of a non-unique row?

Your formula looks very strange to me, perhaps try:
=ArrayFormula(IF($C$2:$C="","",IF(COUNTIF($A$2:$A$100,A2:A100)=1,"Unique","Not Unique")))

It'll need a Row number helper column:
J1 =ARRAYFORMULA(row(A:A))
Then, the magic formula, where 10 is the column ID for the helper column
=ARRAYFORMULA(if(VLOOKUP(A:A,A:J,10,false)=row(A:A),"Unique","Not Unique"))
The vlookup returns the first row number in the helper column where the value in A:A is found and compares it to the currently calculated row.

Related

Array formula with filter and index values depending on countif

I need an array formula only in column Date_2 with results like on screenshot and that will
insert last day of month depending on Date_0 (if bunch of Color&Fruit&Meal doesn't repeat in table)
insert first minimum date of column Date_1 (if bunch of Color&Fruit&Meal repeats first time) - 1
insert second minimum date of column Date_1 (if bunch of Color&Fruit&Meal repeats second time) - 1
and so on...
Is is possible to solve it with array formula?
I've tried but I can't..
=ArrayFormula(IF(A2:A="","",IF(COUNTIF(B2:B&C2:C&D2:D,B2:B&C2:C&D2:D)>1,INDEX(FILTER(B2:E,E2:E<>""),1,4),EOMONTH(A2:A,0))))
Google Sheets
I'm not quite sure what you need for Date_1 but try this arrayformula in cell F2 for Date_2:
=ARRAYFORMULA({"Date_2";if(IF(B2:B&""&C2:C&""&D2:D<>"",if(A2:A<>"",COUNTIFS(B2:B&"|"&C2:C&"|"&D2:D,B2:B&"|"&C2:C&"|"&D2:D,ROW(A2:A),"<="&ROW(A2:A)),),)=1,eomonth(A2:A,0),)})
I've added a duplicate sheet ("Erik Help") with the following formula in F1:
=ArrayFormula({"Date_2";IF(A2:A="",,IFERROR(VLOOKUP(B2:B&C2:C&D2:D&TEXT(COUNTIFS(B2:B&C2:C&D2:D,B2:B&C2:C&D2:D,ROW(A2:A),"<="&ROW(A2:A))+1,"000"),{B2:B&C2:C&D2:D&TEXT(COUNTIFS(B2:B&C2:C&D2:D,B2:B&C2:C&D2:D,ROW(A2:A),"<="&ROW(A2:A)),"000"),E2:E},2,FALSE)-1,EOMONTH(A2:A,0)))})
This formula creates the header (which you can change within the formula) and all results for Column F.
To lookup the "next instance of the group if there is one," I just wrote the formula to VLOOKUP that grouping plus a text rendering of the COUNTIFS-as-of-that-row-plus-1 for that grouping within a virtual array of each-grouping-plus-unique-count-thus-far in one column and the E2:E data in the next column. For instance, for Row 2, the formula VLOOKUPs redapplepie002
(002 being the text rendition of 001, which is the count of redapplepie as of row 2).

Exclude current row from VLOOKUP?

When using VLookup is there a way to exclude the current row?
I'm trying to determine the following:
If two rows have the same value in column A,
check if they have the same value in column B.
It seems to me that
=exact(B2,vlookup(A2,A:C,2,FALSE))
should be able to do that, the only thing I can't figure out is how to ignore the current row so it doesn't compare itself to itself.
Just starting the vlookup range one row lower than the current row would work, except it's possible that the row with the matching value in column A is either above or below the current row.
Thanks!
If two rows have the same value in column A,
check if they have the same value in column B.
use:
=ARRAYFORMULA(IF(A2:A&B2:B="",,COUNTIFS(
FLATTEN(QUERY(TRANSPOSE(IFERROR(CODE(REGEXEXTRACT(A2:A&B2:B,
REPT("(.)", LEN(A2:A&B2:B)))))),,9^9)),
FLATTEN(QUERY(TRANSPOSE(IFERROR(CODE(REGEXEXTRACT(A2:A&B2:B,
REPT("(.)", LEN(A2:A&B2:B)))))),,9^9)))>1))
Use COUNTIFS instead:
=COUNTIFS(A:A,A2,B:B,B2)>1
You can use the range you want to check for the vlookup
So you can use this query: =exact(A1,vlookup(A1,A1:B4,2,FALSE))
Note: A1:B4 is the range for the vlookup.
For more about vlookup you can check: Link.

Is there a way to use an array formula to keep my formula (to add specific columns) when rows are inserted?

I'm setting up a spreadsheet that has specific columns summed in each row, but I need the formula to be included when a row is inserted.
The current formula also includes a statement to make a 0 value, if a check box is checked in the last column:
=IF(T2=FALSE, SUM(I2,K2,L2,M2,N2,O2), 0)
Is there a way I can do this using an array formula?
Here is a formula which will give a sum for columns I to O in each row, ignoring column J:
=ArrayFormula(if(I2:I="","",if(T2:T<>FALSE,0,I2:I+sumif(row(K2:O)+0*column(K2:O),row(K2:O),K2:O))))
but this assumes all rows that have data will have a number in column I.
If this isn't the case, you could go on to test columns individually like this:
=ArrayFormula(if((I2:I="")*(K2:K=""),"",if(T2:T<>FALSE,0,I2:I+sumif(row(K2:O)+0*column(K2:O),row(K2:O),K2:O))))
and so on up to column O if necessary, or maybe column T is always completed and you could test that - it depends how your data actually looks.
Note 1
row(K2:O)+0*column(K2:O)
is necessary to generate an array which is has the same dimensions as K2:O as required by SUMIF.
Note 2
There's also the MMULT approach to getting the row sums as demonstrated here
={"AAA"; ARRAYFORMULA(IF(LEN(T2:T), IF(T2:T=FALSE, I2:I+K2:K+L2:L+M2:M+N2:N+O2:O, 0), ))}

Arrayformula sum one column until this row

I'm trying to make an array formula which sums up all the rows until this row.
For clarification column a will be the input and column b would be the output. I'm looking for a way to do this with an arrayformula.
a1:1 b1:1a2:2 b2:3a3:5 b3:8a4:3 b4:11
I tried to use =ARRAYFORMULA(SUM(INDIRECT("F1:"&ADDRESS(ROW(),COLUMN(F2:F))))) but this doesn't work.
How about
=arrayformula(sumif(row(A1:A4),"<="&row(A1:A4),A1:A4))
The sumif is evaluated separately for each value in the criteria part so:
In the first row of the output array you have
=sumif(row(A1:A4),"<=1",A1:A4)
giving you just the first row of column A.
In the second row of the output array you have
=sumif(row(A1:A4),"<=2",A1:A4)
giving you the sum of the first 2 rows and so on.
Since OP changed the question with a clarification, A different answer is submitted below:
B1:
=ARRAYFORMULA(MMULT(transpose(A1:A5)*--IF(row(1:5),COLUMN(A:E)<=row(1:5)),ROW(1:5)^0))

How to use INDEX() inside ARRAYFORMULA()?

I am trying to use the INDEX() formula inside an ARRAYFORMULA(). As a simple (non-sense) example, with 4 elements in column A, I expected that the following array formula entered in B1 would display all four elements from A in column B:
=ARRAYFORMULA(INDEX($A$1:$A$4,ROW($A$1:$A$4)))
However, this only fills field B1 with a the value found in A1.
When I enter
=ARRAYFORMULA(ROW($A$1:$A$4))
in B1, then I do see all numbers 1 to 4 appear in column B. Why does my first array formula not expand similar like the second one does?
The INDEX function is one that does not support "iteration" over an array if an array is used as one of its arguments. There is no documentation of this that I know of; it simply is what it is. So the second argument will always default to the first element of the array, which is ROW(A1).
One clumsy workaround to achieve what you require relies on a second adjacent column existing next to the source data* (although it is unimportant what values are actually in that second column):
=ArrayFormula(HLOOKUP(IF(ROW($A$1:$A$4);$A$1);$A$1:$B$4;ROW($A$1:$A$4);0))
or indeed something like:
=ArrayFormula(HLOOKUP(IF({3;2;4;1};$A$1);$A$1:$B$4;{3;2;4;1};0))
edit 2015-06-09
* This is no longer a requirement in the newest version of Sheets; the second argument in the HLOOKUP can just be $A$1:$A$4.
Here is a tip for using vlookup with an array, so that even if the columns are moved later on the formula will still work correctly....
In general, configure the vlookup so that it's reading only 2 columns and returning the second. This can be done by inputting only the 2 columns required, rather than a range and column index.
Example:
Replace the following formula which would fail if columns are moved
=arrayformula( vlookup(C:C, booking!$A:$E ,5 ,false) )
with this formula which will continue to work even if columns are moved
=arrayformula( vlookup(C:C, {booking!$A:$A,booking!$E:$E} ,2 ,false) )
Note, you can also simulate the index function using vlookup.
Example:
Column R:R contains the row index numbers for looking up data in column booking!$A:$A
=arrayformula(vlookup(R:R ,arrayformula({row(booking!$A:$A), booking!$A:$A}),2 , false))
It's a nested array, so it can be helpful to test in stages, eg just the inner part for one example, eg return entry in row 10:
=vlookup(10 ,arrayformula({row(booking!$A:$A), booking!$A:$A}),2 , false)

Resources