Pivot Table - Count unique values - Excel 2010
Solution 1
You can create a new column and add the formula:
=IF(COUNTIFS($A$2:A2,A2,$B$2:B2,B2)>1,0,1)
And pivot on this column:
Solution 2
Wouldn't another option be to concatenate the two columns and then remove duplicates? Using the image in Jerry's post, the steps would be:
- Insert column D
- In column D, enter the formula:
=CONCATENATE(A2," ",B2)
This should give you the result "week 1 USER_A" for row 2, "week 1 USER_B" for row 2, and so on.
- Under the 'Data' tab, select "Highlight Duplicates"
- Select only column D, then click OK
You should now be able to count only unique instances of columns A and B. That's what I've done in the past; hopefully I wasn't doing it entirely the wrong way! :-)
Solution 3
Since you did not specify where your data is coming from.
I will assume your data is stored on an SQL database, one can use a partition count or a row_number partition count to achieved those results.
Completing the solution provided by Jerry, the 'Count of users' column can be achieve as follows from SQL
case when row_number() over (partition by Week order by Users) = 1 then 1 else 0 end as [Unique?]
So this actually does a little bit more, first partitions the result set by distinct Week, orders the Users column and assigns a sequential id to every row on the partitions. We basically filter out the number 1 row in every partition.
If data does not come from SQL, disregard.
NillsF
Updated on June 15, 2020Comments
-
NillsF about 4 years
I have a pivot table in excel 2010 based on a network output. I would like to have a count of unique values per week of users who posted on the network.
I found this topic: Simple Pivot Table to Count Unique Values which would add an extra column to my data. Problem for me is, I need unique values per week, not over all the table.
Example input:
week 1 USER_A message1 week 1 USER_B message2 week 1 USER_A message3 week 2 USER_A message4 week 2 USER_B message5 week 2 USER_C message6
What excel actually does is when I ask for a count, is it gives 3 as a count both for week 1 as for week 2. I need the count for week 1 to be 2 (as there are 2 users) and the count for week 2 to be 3 (as there are 3 users).
Anyone know how this can be done?