4. In the Value Field Settings dialog, click Summarize Values By tab, and then scroll to click Distinct Count option, see screenshot: 5. And then click OK, you will get the pivot table which count only the unique values.
You can use the combination of the SUM and COUNTIF functions to count unique values in Excel. The syntax for this combined formula is = SUM(IF(1/COUNTIF(data, data)=1,1,0)). Here the COUNTIF formula counts the number of times each value in the range appears.
To see the unique counts in a pivot table: Create a Pivot Table from this data, with Region in the Rows area. Add Unique, Units and Value in the Values area. Change the "Unique" heading to "Count of Person" or "Person "
In the Calculations group, click Fields, Items, & Sets, and then click Calculated Field. Click Add to save the calculated field, and click Close. The CountB field appears in the Values area of the pivot table layout, and in the field list in the PivotTable Field List.
UPDATE: You can do this now automatically with Excel 2013. I've created this as a new answer because my previous answer actually solves a slightly different problem.
If you have that version, then select your data to create a pivot table, and when you create your table, make sure the option 'Add this data to the Data Model' tickbox is check (see below).
Then, when your pivot table opens, create your rows, columns and values normally. Then click the field you want to calculate the distinct count of and edit the Field Value Settings:
Finally, scroll down to the very last option and choose 'Distinct Count.'
This should update your pivot table values to show the data you're looking for.
Insert a 3rd column and in Cell C2
paste this formula
=IF(SUMPRODUCT(($A$2:$A2=A2)*($B$2:$B2=B2))>1,0,1)
and copy it down. Now create your pivot based on 1st and 3rd column. See snapshot
I'd like to throw an additional option into the mix that doesn't require a formula but might be helpful if you need to count unique values within the set across two different columns. Using the original example, I didn't have:
ABC 123
ABC 123
ABC 123
DEF 456
DEF 567
DEF 456
DEF 456
and want it to appear as:
ABC 1
DEF 2
But something more like:
ABC 123
ABC 123
ABC 123
ABC 456
DEF 123
DEF 456
DEF 567
DEF 456
DEF 456
and wanted it to appear as:
ABC
123 3
456 1
DEF
123 1
456 3
567 1
I found the best way to get my data into this format and then be able to manipulate it further was to use the following:
Once you select 'Running total in' then choose the header for the secondary data set (in this case it would be the header or column title of the data set that includes 123, 456 and 567). This will give you a max value with the total count of items in that set, within your primary data set.
I then copied this data, pasted it as values, then put it in another pivot table to manipulate it more easily.
FYI, I had about a quarter million rows of data so this worked a lot better than some of the formula approaches, especially ones that try to compare across two columns/data sets because it kept crashing the application.
I found the easiest approach is to use the Distinct Count
option under Value Field Settings
(left click the field in the Values
pane). The option for Distinct Count
is at the very bottom of the list.
Here are the before (TOP; normal Count
) and after (BOTTOM; Distinct Count
)
See Debra Dalgleish's Count Unique Items
It is not necessary for the table to be sorted for the following formula to return a 1 for each unique value present.
assuming the table range for the data presented in the question is A1:B7 enter the following formula in Cell C1:
=IF(COUNTIF($B$1:$B1,B1)>1,0,COUNTIF($B$1:$B1,B1))
Copy that formula to all rows and the last row will contain:
=IF(COUNTIF($B$1:$B7,B7)>1,0,COUNTIF($B$1:$B7,B7))
This results in a 1 being returned the first time a record is found and 0 for all times afterwards.
Simply sum the column in your pivot table
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With