Excel - distinct count

%3CLINGO-SUB%20id%3D%22lingo-sub-2380529%22%20slang%3D%22en-US%22%3EExcel%20-%20distinct%20count%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2380529%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20hope%20someone%20can%20help.%20I%20need%20to%20do%20a%20distinct%20count%20in%20excel%20of%20the%20'Opportunity%20ID'%20(column%20G%20in%20'Campaign%20Data'%20tab.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20outcome%20would%20need%20to%20look%20like%20Pivot%202%20in%20the%20'Pivot%20tab'%20-%20but%20not%20necessarily%20in%20a%20pivot%20as%20i'll%20create%20a%20table.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20question%20is%2C%20how%20many%20students%20(opportunity%20ids)%20attended%20one%20of%20the%20campaign%20types%20at%20least%20%3CSTRONG%3Eonce%3C%2FSTRONG%3E.%20For%20example%2C%20111%20opportunity%20IDS%20are%20counted%20for%20Vertical%20Area%20%3D%20Spain%20%26amp%3B%20Portugal%20and%20Campaign%20Type%26nbsp%3B%20%3D%20Open%20Day.%20But%205%20of%20the%20111%20could%20be%20the%20same%20person%20it's%20just%20they%20went%20to%205%20open%20days.%20I%20want%20to%20know%20if%20they%20went%20to%20at%20least%201.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20Pivot%201%2C%20if%20I%20count%20column%20A%20that%20gives%20me%20the%20correct%20number.%20It's%20just%20when%20I%20aggregate%20I%20get%20the%20duplicates.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20this%20makes%20sense!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EJenny%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2380529%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%20on%20Mac%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2381135%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20-%20distinct%20count%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2381135%22%20slang%3D%22en-US%22%3EThank%20you!%20How%20would%20I%20then%20get%20a%20nice%20table%20displayed%20of%20Vertical%20Area%20as%20rows%2C%20Campaign%20Type%20at%20the%20top%20and%20counting%20the%20unique%20opportunity%20IDS%20as%20values%3F%20May%20also%20need%20to%20filter%20by%20other%20values%20(i'e%20column%20J%20and%20M).%20Thanks!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2381220%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20-%20distinct%20count%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2381220%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F668941%22%20target%3D%22_blank%22%3E%40JennySommet%3C%2FA%3E%26nbsp%3BI%20would%20recommend%20you%20use%20the%20built%20in%20PivotTable%20functionality%20but%20maybe%20there%20is%20some%20reason%20you%20need%20to%20not%20use%20it%20(but%20I%20suspect%20we%20could%20solve%20that%20issue).%3C%2FP%3E%3CP%3EIn%20any%20case%2C%20I%20did%20much%20the%20same%20as%20I%20showed%20above%20using%20UNIQUE%20to%20get%20the%20header%20row%20and%20the%20left%20column%20and%20then%20COUNTA(UNIQUE(FILTER()))%20to%20count%20how%20many%20match%20the%20header%20and%20the%20left%20column.%3C%2FP%3E%3CP%3Esee%20attached.%26nbsp%3B%20I%20didn't%20take%20the%20time%20to%20remove%20the%20%220%22%20or%20the%20headers%20themselves.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2381366%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20-%20distinct%20count%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2381366%22%20slang%3D%22en-US%22%3EAhh%20this%20is%20great%20thank%20you!%20What%20is%20the%20difference%20between%20cell%20C10%20in%20'sheet%201'%20value%20%3D%20490%20and%20cell%20AE24%20in%20'Pivot'%20value%20%3D%20221%20please%3F%3CBR%20%2F%3E%3CBR%20%2F%3EWhat%20I%20would%20need%20to%20show%20in%20table%20is%20for%20example%2C%20a%20total%20value%20of%20348%20for%20Spain%20and%20Portugal%3F%20i.e%20count%20of%20all%20opportunity%20ids%20in%20Spain%20and%20Portugal%20-%20see%20Pivot%201.%20To%20see%20this%20348%20by%20Campaign%20type%20I%20would%20need%20to%20count%20the%20opportunity%20ID%20once%20per%20campaign%20type.%20i.e%20if%20Harry%20appeared%2010%20times%20in%20campaign%20type%20%3D%20organic%2C%20i%20only%20want%20to%20that%20he%20appeared%20once.%20Hope%20I%20make%20sense!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2382375%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20-%20distinct%20count%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2382375%22%20slang%3D%22en-US%22%3Eso%20AE24%20in%20'Pivot'%20of%20221%20is%20filtered%20by%20School%20Term%20Semester.%20Without%20that%20filter%20it%20shows%20628%20which%20I'm%20guessing%20is%20because%20there%20are%20138%20non-unique%20values.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2382704%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20-%20distinct%20count%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2382704%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F570951%22%20target%3D%22_blank%22%3E%40mtarler%3C%2FA%3E%26nbsp%3BHow%20do%20I%20reflect%20the%20Count%20opp%20IDS%20348%20in%20Pivot%2C%20to%20show%20in%20your%20table%20on%20'sheet%201'%20by%20campaign%20type%20please%3F%20To%20be%20clear%2C%20the%20total%20of%20row%2010%20on%20'sheet%201'%2C%20needs%20to%20be%20348.%20I%20tried%20adding%20in%20the%20School%20Term%20Semester%20to%20your%20calculation%2C%20it%20didn't%20work.%20Thanks%20-%20almost%20there!!!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2380778%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20-%20distinct%20count%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2380778%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F668941%22%20target%3D%22_blank%22%3E%40JennySommet%3C%2FA%3E%26nbsp%3B%20If%20you%20are%20using%20Excel%20365%20you%20will%20have%20the%20UNIQUE%20function.%26nbsp%3B%20If%20you%20also%20need%20to%20FILTER%20that%20is%20also%20available.%26nbsp%3B%20For%20example%20the%20following%20will%20filter%20by%20any%20Vertical%20Region%20starting%20with%20%22Spain%22%20and%20show%20only%20the%20Unique%20results%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DUNIQUE(FILTER('Campaign%20Data'!G%3AG%2CLEFT('Campaign%20Data'!M%3AM%2C5)%3D%22Spain%22))%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Contributor

Hello,

 

I hope someone can help. I need to do a distinct count in excel of the 'Opportunity ID' (column G in 'Campaign Data' tab.

 

The outcome would need to look like Pivot 2 in the 'Pivot tab' - but not necessarily in a pivot as i'll create a table. 

 

The question is, how many students (opportunity ids) attended one of the campaign types at least once. For example, 111 opportunity IDS are counted for Vertical Area = Spain & Portugal and Campaign Type  = Open Day. But 5 of the 111 could be the same person it's just they went to 5 open days. I want to know if they went to at least 1. 

 

In Pivot 1, if I count column A that gives me the correct number. It's just when I aggregate I get the duplicates.

 

Hope this makes sense!

 

Thanks

 

Jenny

 

 

11 Replies

@JennySommet  If you are using Excel 365 you will have the UNIQUE function.  If you also need to FILTER that is also available.  For example the following will filter by any Vertical Region starting with "Spain" and show only the Unique results:

=UNIQUE(FILTER('Campaign Data'!G:G,LEFT('Campaign Data'!M:M,5)="Spain"))
Thank you! How would I then get a nice table displayed of Vertical Area as rows, Campaign Type at the top and counting the unique opportunity IDS as values? May also need to filter by other values (i'e column J and M). Thanks!

@JennySommet I would recommend you use the built in PivotTable functionality but maybe there is some reason you need to not use it (but I suspect we could solve that issue).

In any case, I did much the same as I showed above using UNIQUE to get the header row and the left column and then COUNTA(UNIQUE(FILTER())) to count how many match the header and the left column.

see attached.  I didn't take the time to remove the "0" or the headers themselves.

Ahh this is great thank you! What is the difference between cell C10 in 'sheet 1' value = 490 and cell AE24 in 'Pivot' value = 221 please?

What I would need to show in table is for example, a total value of 348 for Spain and Portugal? i.e count of all opportunity ids in Spain and Portugal - see Pivot 1. To see this 348 by Campaign type I would need to count the opportunity ID once per campaign type. i.e if Harry appeared 10 times in campaign type = organic, i only want to that he appeared once. Hope I make sense!
so AE24 in 'Pivot' of 221 is filtered by School Term Semester. Without that filter it shows 628 which I'm guessing is because there are 138 non-unique values.

@mtarler How do I reflect the Count opp IDS 348 in Pivot, to show in your table on 'sheet 1' by campaign type please? To be clear, the total of row 10 on 'sheet 1', needs to be 348. I tried adding in the School Term Semester to your calculation, it didn't work. Thanks - almost there!!!

@JennySommet I updated the formula to eliminate the "nulls" as counting as 1 (i.e. many of those 1 values should have been 0s).  I also applied your added criteria to the whole table.  but other than that I don't see any other errors.  Are you sure that row sum is 348?  Is there another filter/criteria that 348 is based on?  Another possibility is that some of the opp IDS values that are supposed to be the same have some slight difference?  I tried adding TRIM and CLEAN to see if there were extra spaces or invisible characters added in some cases (this was not exhaustive), but that made no difference.  Please confirm where that 348 comes from

Thank you! This is great. The 348 is in Pivot 1 - column A, if you count the opp IDS it is 348.

@JennySommet Ah HA!! So you need to decide what you really want/need. Yes the number of unique IDs in Pivot1 is 348 but many of those unique IDs have counts in multiple campaign types. So if you highlight that pivot table (without the totals col or row) and look at the bottom bar that shows counts and totals and look at "Numerical Count", which is the count of cells that have numbers in them, you will see 612 and that exactly matches the 612 from the sum of the corresponding row in Sheet 1.  

That said, I modified the formula in the 1st column of Sheet 1 under campaign_type to exclude the campaign type filter (i.e. now that 1st column is for all campaign types) and now you will see that 348 in that first column.

Hi sorry for not explaining clearly! It is so hard to put into words I want to know what % of my pipeline were 'engaged with'. So out of the 348 for the Spain & Portugal Pipeline, what % attended each of the campaign types. I know each one attended multiple ones, but did they attend at least one?
ok you sort of lost me there. you want a % for each campaign type? So the latest file I sent you can divide the number for an individual campaign by the first column which is the total for any campaign. BUT that is a % of those that went to something, went to that campaign vs not going to THAT campaign type, it is not a list of % values for each campaign relative to EACH OTHER (i.e. those % will not add up to 100%). As with all statistics, you need to be careful defining exactly what you want and understand the values you are calculating. For example if you look at that % for Organic it is close to 50% of that 348, but that doesn't mean organic is responsible for 50% of all unique IDs encounters but I think it would be correct to say almost 50% of all unique IDs had an organic campaign event.
In any case, I think you have everything you need, now you just need to wield that power carefully