SOLVED

Pivot Table

%3CLINGO-SUB%20id%3D%22lingo-sub-3354462%22%20slang%3D%22en-US%22%3EPivot%20Table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3354462%22%20slang%3D%22en-US%22%3E%3CP%3EI'm%20trying%20to%20have%20a%20pivot%20table%20count%20the%20number%20of%20different%20districts%20in%20a%20column.%20They%20are%20uniquely%20named.%20Putting%20Districts%20into%20the%20value%20field%20with%20count%20value%20just%20counts%20the%20number%20of%20cells.%20How%20can%20I%20ask%20it%20to%20count%20how%20many%20different%20district%20names%20there%20are%20in%20the%20column%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3354462%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3355142%22%20slang%3D%22en-US%22%3ERe%3A%20Pivot%20Table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3355142%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1386487%22%20target%3D%22_blank%22%3E%40McKinney245%3C%2FA%3E%26nbsp%3BIn%20a%20regular%20pivot%20table%20you%20don't%20have%20the%20distinct%20count%20option.%20That's%20only%20when%20you%20add%20it%20to%20the%20Data%20Model%20(PC%20only)%2C%20as%20described%20in%20the%20link%20below.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fexceljet.net%2Fpivot-table%2Fpivot-table-unique-count%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fexceljet.net%2Fpivot-table%2Fpivot-table-unique-count%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20that's%20not%20an%20option%2C%20add%20a%20helper%20column%20to%20the%20data%20set%20with%20a%20formula%20like%20below.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELet's%20say%20the%20Districts%20at%20in%20column%20A%2C%20row%202%20and%20down.%20Enter%20the%20following%20in%20a%20new%20column%20on%20row%202%3A%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3D--(COUNTIF(%24A%242%3AA2%2CA2)%3D1)%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3Eand%20copy%20it%20all%20the%20way%20down.%20This%20will%20produce%20a%20range%20of%201's%20and%200's%20that%20you%20can%20just%20SUM%20or%20put%20in%20the%20pivot%20table%26nbsp%3BValue%20field%20where%20it%20will%20be%20summed%20automatically.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOr%2C%20if%20you%20are%20on%20MS365%20or%20Excel%202021%2C%20use%20COUNTA%20combined%20with%20UNIQUE.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3358672%22%20slang%3D%22en-US%22%3ERe%3A%20Pivot%20Table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3358672%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you!%20The%20Data%20Model%20route%20worked.%20I%20tried%20the%20helper%20column%20too%20just%20for%20kicks%20and%20that%20was%20good%20too!%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

I'm trying to have a pivot table count the number of different districts in a column. They are uniquely named. Putting Districts into the value field with count value just counts the number of cells. How can I ask it to count how many different district names there are in the column?

2 Replies
best response confirmed by Hans Vogelaar (MVP)
Solution

@McKinney245 In a regular pivot table you don't have the distinct count option. That's only when you add it to the Data Model (PC only), as described in the link below.

 

https://exceljet.net/pivot-table/pivot-table-unique-count 

 

If that's not an option, add a helper column to the data set with a formula like below.

 

Let's say the Districts at in column A, row 2 and down. Enter the following in a new column on row 2:

=--(COUNTIF($A$2:A2,A2)=1)

and copy it all the way down. This will produce a range of 1's and 0's that you can just SUM or put in the pivot table Value field where it will be summed automatically.

 

Or, if you are on MS365 or Excel 2021, use COUNTA combined with UNIQUE.

 

@Riny_van_Eekelen 

Thank you! The Data Model route worked. I tried the helper column too just for kicks and that was good too!