How to get unique values in a column using excel formula - excel-formula

I have Excel Data like below
JID Val
1001 22
1030 6
1031 14
1041 8
1001 3
2344 8
1030 8
2344 6
1041 8
How do i get the unique JID values like below using formula?
UJID
1001
1030
1031
1041
2344

Here is a solution to get a list of unique items from your tables
There is two parts to this solution.
Part 1) Unique Count
{=SUM(IF(FREQUENCY(IF($A$2:$A$10<>"",MATCH($A$2:$A$10,$A$2:$A$10,0)),ROW($A$2:$A$10)-ROW($A$2)+1),1))}
This will count the number of unique items in your data table and will ignore any blanks
*Note this is an array formula and you will need to use "Ctrl" + "Shift" + "Enter" to use
Part 2) Unique List
This formula will give you the list of unique items in your table
={IF(ROWS($E$5:E5)>$E$2,"",INDEX($A$2:$A$10,SMALL(IF(FREQUENCY(IF($A$2:$A$10<>"",MATCH($A$2:$A$10,$A$2:$A$10,0)),ROW($A$2:$A$10)-ROW($A$2)+1),ROW($A$2:$A$10)-ROW($A$2)+1),ROWS($E$5:E5))))}
again this is an array formula. You can then drag this formula down to get all the unique items.
This formula is a dynamic formula, meaning you can set the data range past your current data range and the list will update as you enter new values.
*Here is a great video to watch to understand this further
https://www.youtube.com/watch?v=3u8VHTvSNE4

You can use the remove duplicate function
Select the column range
Go to Data Tab
then click on Remove Duplicates

I think I've found a more elegant workaround without array-functions or built-in functions:
1st column (ID):
this is the array from we'd like to select distinct values
2nd column (criteria):
checks whether this is the first occurrence
=IF((ROW()-1)=MATCH(A2,$A$2:$A$500,0),1,0)
3rd column (cumulative):
=SUM($B$2:B2)
4th column (count):
this is constant 1
5th column (unique ID):
=OFFSET($A$2,MATCH(ROW()-1,$C$2:$C$501,0)-1,)
6th column (count):
=SUMIF(A2:A21,F2,D2:D21)

Related

How to get maximum number and name from 2 columns? (Excel)

I have this (example):
Luffy 320
Coby 350
Zoro 180
Now I want to show the max from this info, with number and text (in seperate cells) like this:
col 1 col 2 col 3
1st 350 Coby
2nd 320 Luffy
3rd 180 Zoro
The 2nd Column no problem with the MAX() formula.
For the 3rd column to get the text I've tried the MAX(...) and INDEX(...) formulas but nothings working ...
Can anyone help me?
You first need to get which value is the largest, second largest and so on.
You can use the function LARGE(range, n) for this.
So in your col 2 use this formula:
=LARGE(B:B,1)
=LARGE(B:B,2)
=LARGE(B:B,3)
Assuming B is the column with the values.
Then we need to match this value and get the name
=INDEX(A:A,MATCH("the above calculated cell",B:B,0))
With the above calculated cell I mean the LARGE function cell. And assuming column A is the column with the names.
This should give you a dynamic table that will update when values or names change.
I'm not sure how you manage to get that column 2 using MAX formula since it only outputs the largest number of the inputs and thus can't output 2nd and 3rd position.

Counting unique list of items from range based on criteria from other ranges

I have a file with data in the following format:
text value1 value2
Given value 1 and value 2 meet some criteria, find all the unique text values.
The exact data looks like this:
john 10 20
john 15 35
mark 20 10
mark 25 15
tom 25 40
lee 16 50
If val 1 <=25 and value 2 <=35 the number of unique text = 2 (john and mark)
I have to do this using formulas not filters.
I've been trying combinations of frequency, countifs, sumproducts and a whole range of other methods and can't seem to hit what I'm looking for.
Assuming that text, value1, and value2 are in columns A, B, and C respectively ...
In D1, enter the formula =IF(AND(B1<=25,C1<=35),A1,"") and copy it down the column
Use the formula =SUMPRODUCT((D:D<>"")/COUNTIF(D:D,D:D&"")) for your answer
If you want to list the unique values rather than count them, something like this:-
=IFERROR(INDEX(A$2:A$7,MATCH(0,IF((B$2:B$7>25)+(C$2:C$7>35),1,COUNTIF(E$1:E2,A$2:A$7)),0)),"")
entered as an array formula starting in E2 ( and assuming that you are using columns A,B and C for your data.
See this reference for explanation.
The following formula will do what you are asking:
=SUM(IF(FREQUENCY(IF(B2:B7<=25,IF(C2:C7<=35,MATCH(A2:A7,A2:A7,0),""),""),IF(B2:B7<=25,IF(C2:C7<=35,MATCH(A2:A7,A2:A7,0),""),""))>0,1))
This is an array formula so confirm it with Ctrl-Shift-Enter.
I referred to this webpage.
Also found a shorter one:
=SUM(--(FREQUENCY(IF(B2:B7<=25,IF(C2:C7<=35,COUNTIF(A2:A7,"<"&A2:A7),""),""),COUNTIF(A2:A7,"<"&A2:A7))>0))
Found and modified from hre.

Get average of cells conditionally in Excel 2010

I have a table in Excel with 2 columns. Column A (Owner) has a list of names. Column B (Duration) has a list of numbers. I need to get the average of numbers for each of the owner. So for James it would be (4 + 5 + 18) / 3. I know how to get the average in Excel but I don't know how to conditional say:
Use the value in Column B if value in A = "James"
A B
---------------
Owner Duration
James 4
Dan 67
Ger 3
James 5
Ger 75
James 18
The AVERAGEIF function will allow you to do this.
=AVERAGEIF(A2:A7,"James",B2:B7)
The first argument is the range which will be subject to the criteria
The second argument is the criteria.
The third argument is the range (corresponding to the first range) with values to be averaged.
There is also a SUMIF, COUNTIF, and others.
You will need to do this in a pivot table.
Select all your data.
Go to Insert >> pivot table >> click ok
Select both columns (COLA, COLB) from the list of fields
available on the right.
By default COLB will go under VALUES.
Click on the arrow that says Sum of COLB >> click on value field
settings >> Select Average function instead of sum.
Check this link https://support.office.com/en-us/article/Create-or-delete-a-PivotTable-or-PivotChart-report-d09e4d07-8cd6-4b60-afad-8fb67418800f?CorrelationId=78b545a8-649b-400a-9941-a23ef409c95b&ui=en-US&rs=en-US&ad=US#_Toc263767342 for more info on pivot tables

Excel Function to sum values from table based on a comma separated list

I am trying to find a function that will look at a table and sum all the values where the string appears in my comma separated list. I can get sumproduct to work if my list is separated into different cells, but I need the list to be in one cell. Here is what I'm looking for:
List in Cell A1: 2000,2100,2300
Table: A10:B16
A B
2000 20
2100 25
2200 32
2300 65
2400 72
2500 12
2600 2
I'm looking for a result of: 110
Any help would be appreciated.
Thanks!
I am assuming that you can use another column but not for your list?
If so you can use the formula below in column C
=IF(ISERROR(FIND(A2,$A$1,1))=FALSE,TRUE,FALSE) with A2 being the 1st cell in which the data is contained.
This is searching through your comma separated list and evaluating against the data in column B whether it exists in the list, if so then returns true if not false.
Now you can use the SUMIF function to return those matching true in your new column C.
=SUMIF(C2:C8,TRUE,B2:B8)
If having the evaluation column C is a problem for other users you could always hide it

Sum the values in Excel cells depending on changing criteria

In an Excel spread sheet I have three columns of data, the first column A is a unique identifier. Column B is a number and column C is either a tick or a space:
A B C
1 d-45 150 √
2 d-46 200
3 d-45 80
4 d-46 20 √
5 d-45 70 √
Now, I wish to sum the values in column B depending on a tick being present and also relative to the unique ID in column A. In this case rows 1 and 5. Identifying the tick I use
=IF(ISTEXT(C1),CONCATENATE(A1))
&
=IF(ISTEXT(C1),CONCATENATE(B1)).
This leaves me with two arrays of data:
D E
1 d-45 150
4 d-46 20
5 d-45 70
I now want to sum the values in column E depending on the ID in column D, in this case row 1 and 5. I can use a straight forward SUMIFS statement to specify d-45 as the criteria however this unique ID will always change. Is there a variation of SUMIFS I can use?
I also wish to put each new variation of ID number into a separate header with the summed totals underneath, that is:
A B
1 d-45 d-46
2 220 20
etc...
You can try this:
To get the distinct ID's write (in H1 then copy right):
This one is an array formula so you need Ctrl Shift Enter to enter the formula
=INDEX($A$1:$A$5;SMALL(IF(ROW($A$1:$A$5)-ROW($A$1)+1=MATCH($A$1:$A$5;$A$1:$A$5;0);ROW($A$1:$A$5)-ROW($A$1)+1;"");COLUMNS($A$1:A1)))
Now to get the sum (H2 and copy right)
=SUMPRODUCT(($A$1:$A$5=H1)*ISTEXT($C$1:$C$5)*$B$1:$B$5)
Data in the example is in A1:C5
Depending on your regional settings you may need to replace ";" field separator by ","
Try this,
SUMIFS
=SUMIFS(B1:B5,A1:A5,"=d-45",C1:C5,"<>")
where "<>" means that the cell is not empty...

Resources