Identify if list contains not unique values without countif in a helper column - excel

A B C
1 Product A 1 Error
2 Product B 1
3 Product C 2
4 Product C 2
5 Product D 1
6 Product E 1
7
8
In the table above I want to identify if the values in Column A are unique.
If there is at least one value which is not unique Error should be displayed in Cell C1.
In order to achieve this I went with helper Column B and with the following formulas:
Column B `=COUNTIF($A$1:$A$6,A2)`
Cell C1 =`IF(COUNTA($A$1:$A$6)<SUM($B$1:$B$6),"Error","OK")`
All this works fine.
Now, I am wondering if there is also way to avoid the helper column.
Basically, a formula that goes through Column A and if it identfies at least one not-unique value it should display Error in Cell C1.

use:
=IF(MAX(COUNTIF($A$1:$A$6,$A$1:$A$6))>1,"Error","OK")
This is an array formula and depending on one's version will require the confirmation of Ctrl-Shift-Enter instead of Enter when exiting edit mode.
If one has the dynamic formula UNIQUE() then:
=IF(COUNTA(UNIQUE($A$1:$A$6))<>COUNTA($A$1:$A$6),"Error","OK")
As a normal formula.
Another formula, that will work in Conditional formatting:
=SUMPRODUCT(--(MATCH($A$1:$A$6,A:A,0)<>ROW($A$1:$A$6)))>0

Related

Matching multiple value in excel using index and match

I used index and match to identify the values of the table and matched it. However I am facing trouble when I try to get b and c, a is matched correctly
A. B C D.
1 a b c
2 fruit1 a
3 fruit0
4 fruit3
5 fruit5 a
E F
1 fruit1 a
2 fruit0 c
3 fruit3 b
4 fruit5 a
My formula is
=Iferror(if(index(($f$1:$f$4), match($A2,$e$1:$e$4,0),match(b$2,$f$1:$f$4,0)) = b$2,index(($f$1:$f$4), match($A2,$e$1:$e$4,0),match(b$2,$f$1:$f$4,0)), ""),"")
If your data table is in E1:F4, and you are trying to look up the fruit names that appear in column A starting at A2, and place the correct letter next to them in column B, then there's no need for the IF and the sequences of MATCHes.
All you need is this, pasted into cell B2 and copied down, is this:
=IFERROR(INDEX($F$1:$F$4,(MATCH(A2,$E$1:$E$4,0))),"")
An easier approach to this is just:
=VLOOKUP(A2,$E$1:$F$4,2,FALSE)
or to be safer:
=IFERROR(VLOOKUP(A2,$E$1:$F$4,2,FALSE),"")
And if you have access to O365 Excel and the newer XLOOKUP function, you can use the following examples. XLOOKUP incorporates the "not found" result so you don't have to do a separate IFERROR. Do do it on a cell-by-cell basis as you had before, put this in B2 and copy it down:
=XLOOKUP(A2,$E$1:$E$4,$F$1:$F$4,"",0)
If you want to go one step further, you can apply the XLOOKUP as an array or "spill" formula, you change the lookup_value to be the A1:A4 and it does the rest. Place this in B2 and it will fill B2 through B5:
=XLOOKUP(A2:A5,$E$1:$E$4,$F$1:$F$4,"",0)

Formula to Return Text in the Row of Largest Number

Column A Has Text & Columns B, C & D contain numbers.
For Ex.)
A... …B C D
John 4 6 2
Dave 4 6 4
Mike 4 5 1
Bill 2 5 9
I would like a cell to return the name in column A that has the Largest Number in Column B. And if there are similar numbers, go to the next column and determine which is highest, and if that is tied go to the next column and so on.
Any help would be appreciated.
We can de-conflict ties.In E1 enter:
=B1 + C1/(10*MAX(C:C))+D1/(100*MAX(D:D))
and copy down. Then in another cell enter:
=INDEX(A:A,MATCH(MAX(E:E),E:E,0))
EDIT#1
This is only good for 3 columns of numbers, but it is very easy to add additional de-confliction terms if necessary:
=B1 + C1/(10*MAX(C:C))+D1/(100*MAX(D:D))+E1/(1000*MAX(E:E))
For an expandable number of rows/columns, use a helper row with the same number of columns as number columns in your data. The formulas below reference the following image (the data are in A1:G7):
B9-->=MAX(B1:B7)
C9 (fill over the remaining columns to G9)-->
=MAX(IF(MMULT(--($B1:B7=$B9:B9),--(ROW(INDIRECT("1:"&COLUMNS($B9:B9)))>0))=COLUMNS($B9:B9),C1:C7))
The following formula will give the answer (shown in A9 above):
=INDEX(A1:A7,MATCH(TRUE,(MMULT(--($B1:G7=$B9:G9),--(ROW(INDIRECT("1:"&COLUMNS($B9:G9)))>0))=COLUMNS($B9:G9)),0))
UPDATE WITH ALTERNATIVE METHOD
Using a helper column instead, again referencing the image below (the data are in A1:G7):
I1 (fill down to I7)-->
=SUM(--(MMULT(SIGN(B1:G1-$B$1:$G$7)*2^(COLUMN(G1)-COLUMN(A1:F1)),--(ROW(INDIRECT("1:"&COLUMNS(B1:G1)))>0))>0))
The following formula will give the answer (shown in J1 above):
=INDEX(A1:A7,MATCH(MAX(I1:I7),I1:I7,))
As a bonus, notice that the helper column corresponds to the order that you would get from sorting the data by each column left-to-right. In other words, you could use the helper column to perform a formula-based multi-column sort on strictly numeric data. For the last image, entering the following array formula into a range with the same dimensions as A1:G7 gives a descending sort on columns B through G:
=IF(A1:A7=A1:A7,INDEX(A1:G7,MATCH(ROW(A7)-ROW(A1:A7),I1:I7,0),))

Create a unique list even if original list contains cells with =""

I have the following Excel spreadsheet:
A B
1 Original List Unique List
2 Product A Product A
3 Product A Product B
4 Product B Product C
5 =""
6 Product A
7 Product C
8 Product B
9 =""
10 Product C
In Column A I have list which contains several products multiple times. My goal is now to create a list of all unique items in Column B.
To achive this I used the formula from this post in Cells B2:B10:
B2:B10 =IFERROR(INDEX($A$2:$A$10,MATCH(SUM(COUNTIF(B$1:B1,$A$2:$A$10)),COUNTIF($A$2:$A$10,"<"&$A$2:$A$10),0)),"")
and I get the following result:
A B
1 Original List Unique List
2 Product A
3 Product A Product A
4 Product B Product B
5 ="" Product C
6 Product A
7 Product C
8 Product B
9 =""
10 Product C
This result comes pretty close to the list I want. The only issue is that the formula cannot handle the formula ="" which is in some cells in Column A. Instead of starting the list in Cell B2 it starts the list in Cell B3.
How do I have to mody the formula so it also works in case there are cells with ="" in the original list?
Could you use excel's built in 'Remove Duplicates' function?:
Range("$A$2:$A$10").RemoveDuplicates Columns:=1, Header:=xlNo
We can use a "helper" column. In C2 enter:
=IF(A2="","",IF(COUNTIF($A$2:A2,A2)>1,"",1+MAX($C$1:C1)))
and copy down. Column C assigns a simple sequential value to each item in column A from which data will be extracted. Then in B2 enter:
=IFERROR(INDEX($A$2:$A$10,MATCH(ROWS($1:1),$C$2:$C$10,0)),"")
and copy down:
Note:
This method uses normal formulas rather than array formulas.
You could use the Advanced Filter.
Use a Formula criteria such as =LEN(A5)>0 where A5 is the first cell with data. And then check the Unique Records Only in the Advanced Filter dialog. You can either filter in place, or to a new location

Getting the next lower value with VLOOKUP

I have the following Excel spreadsheet:
A B C D
1 15.000 Product 1 7.500 Product 2
2 5.000 Product 2
3 1.000 Product 3
4 0 Product 4
5
In Cell C1 I type a random number (in this case 7.500). Now I want that in Cell D1 the corresponding Product is shown to the value in Cell C1.
Since 7.500 does not exist in Column A the next lower value should be used.
In this case 5.000 which belongs to Product 2.
I tried to go with the following formulas in Cell D2 but instead of getting Product 2 I always get Product 4 as a result.
=VLOOKUP(F16,$A$1:$B$4,2,TRUE)
=VLOOKUP(F16,$A$1:$B$4,2)
Do you have any idea how to solve this issue?
For unsorted data you can use below formula:
=INDEX(B1:B4,MATCH(LARGE($A$1:$A$4,COUNTIF($A$1:$A$4,">"&C1)+1),A1:A4,0))
See image for reference
i will try it with addition columns, which indicates the difference between given 7.5 and col A like this: =IF($C$1-A1<0,999999,$C$1-A1) and then get the mininum value like =MIN(E1:E4). then get the according value in column B.
If the order is not guaranteed to be ascending then you can use an array formula (use ctrl+shift+enter instead of just enter to create an array formula)
=INDEX(B2:B5,MATCH((C2-MIN(IF((C2-A2:A5)<0,MAX(A2:A5),C2-A2:A5))),A2:A5,0))

Count with criteria for changing column in excel

I have a data looks like this:
a b c
1 3 4
2 3 3
4 1 2
2 4 2
In another worksheet, I want to do the following calculation:
whenever A1 returns a (header of data worksheet), count number of items that are smaller and equal to 2 in column "a". (result will be 2)
if A1 returns b, count number of items that are smaller and equal to 2 in column "b". (result will be 1).
A1 has already been preset with formula such that it will show a or b or c as conditions changed.
I need the formula to be lean... I actually have 6 headers, so if I keep on using if functions, I will probably have to set 6 if functions in one cell...that can be overwhelming. index match cannot provide a range to work on...Any suggestion? thanks
I don't know vba. If you could provide a workable vba code, i don't mind. but i don't know how to read it...>.< please provide user manual for that. lol, thank you~
If your data is found on Sheet1 and the a is found on column a, b is found on column b etc. enter this formula on then next sheet on b1 when a1 is the column value:
=COUNTIF(INDIRECT("Sheet1!"&a1&":"&a1),"<=2")
The Indirect is for adding text to your reference.
If your data sheet is Sheet1, you could try the array formula:-
=SUM((Sheet1!A1:C1=$A$1)*(Sheet1!A2:C5<=2))
Must be entered with CtrlShiftEnter
(actually there are 3 items less than or equal to 2 in column A)
Or you can use the SUMPRODUCT version if you prefer not to use an array formula:-
=SUMPRODUCT((Sheet1!A1:C1=$A$1)*(Sheet1!A2:C5<=2))
Or you can use this INDEX/MATCH method which is probably more efficient:-
=COUNTIF(INDEX(Sheet1!A2:C5,,MATCH(A1,Sheet1!A1:C1,0)),"<="&2)

Resources