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?
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.
To use Distinct Count option, one should add the data to Data Model. We can insert PivotTables in Excel for the web spreadsheet but to create Power Pivot data models, we will need Excel desktop application. Distinct Count option is available of Excel 365 desktop application, but not in online version.
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:
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:
=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.
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! :-)
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.
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