SOLVED

How to Count instances of a variable within another

%3CLINGO-SUB%20id%3D%22lingo-sub-1512675%22%20slang%3D%22en-US%22%3EHow%20to%20Count%20instances%20of%20a%20variable%20within%20another%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1512675%22%20slang%3D%22en-US%22%3E%3CP%3EComplicated%20to%20explain%20.%20.%20.%20but%20I%20am%20trying%20to%20take%20a%20data%20set%20that%20looks%20something%20like%20this%2C%20with%20varying%20number%20of%20entries%20per%20person%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E1.%26nbsp%3B%20%26nbsp%3B%20person%201%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20A%3C%2FP%3E%3CP%3E2.%26nbsp%3B%20%26nbsp%3B%20person%201%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20A%3C%2FP%3E%3CP%3E3.%26nbsp%3B%20%26nbsp%3B%20person%201%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20B%3C%2FP%3E%3CP%3E4.%26nbsp%3B%20%26nbsp%3B%20person%202%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20A%3C%2FP%3E%3CP%3E5.%26nbsp%3B%20%26nbsp%3B%20person%202%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20B%3C%2FP%3E%3CP%3E6.%26nbsp%3B%20%26nbsp%3Bperson%203%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3BA%3C%2FP%3E%3CP%3E7.%26nbsp%3B%20person%203%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20A%3C%2FP%3E%3CP%3E8.%26nbsp%3B%20person%203%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20A%3C%2FP%3E%3CP%3E9.%26nbsp%3B%20person%203%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20collapse%20it%20(or%20make%20a%20new%20data%20set)%20that%20has%20one%20line%20per%20person%2C%20with%20the%20number%20of%20As%20(and%2For%20Bs)%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%23As%3C%2FP%3E%3CP%3E1.%26nbsp%3B%20%26nbsp%3BPerson%201%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%202%3C%2FP%3E%3CP%3E2.%26nbsp%3B%20%26nbsp%3BPerson%202%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%201%3C%2FP%3E%3CP%3E3.%26nbsp%3B%20%26nbsp%3BPerson%203%3A%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B4%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECan%20Excel%20do%20this%3F%26nbsp%3B%20If%20so%2C%20can%20someone%20advise%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1512675%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1513128%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Count%20instances%20of%20a%20variable%20within%20another%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1513128%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F723989%22%20target%3D%22_blank%22%3E%40ljoseph888%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20such%20sample%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20408px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F204492iBF15F7332F8738DD%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EOne%20variant%3A%3C%2FP%3E%0A%3CP%3EIn%20E2%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DUNIQUE(%24B%242%3A%24B%2410)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3Ein%20F2%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DIFERROR(AGGREGATE(14%2C6%2C1%2F(%24B%242%3A%24B%2410%3DE2)*COUNTIFS(%24B%242%3A%24B%2410%2C%24B%242%3A%24B%2410%2C%24C%242%3A%24C%2410%2C%24C%242%3A%24C%2410)%2C1)%2C%22%22)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3Eand%20drag%20it%20down.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAnother%20variant%20-%20Power%20Query%20as%20in%20attached%20file.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1513426%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Count%20instances%20of%20a%20variable%20within%20another%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1513426%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFollow%20up%20question%20(sorry%2C%20but%20you%20were%20so%20helpful!)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20my%20summary%2C%20I%20would%20like%20to%20include%20additional%20secondary%20variables.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20example%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3Bvar%20a%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20Count%3C%2FP%3E%3CP%3E1.%26nbsp%3B%20Person%201%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20March.%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B2%3C%2FP%3E%3CP%3E2.%26nbsp%3B%20Person%202.%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3BMarch%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%201%3C%2FP%3E%3CP%3E3.%26nbsp%3B%20Person%203%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3BApril%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%204%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETrying%20to%20figure%20it%20out%20on%20my%20own%20.%20.%20.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1513444%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Count%20instances%20of%20a%20variable%20within%20another%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1513444%22%20slang%3D%22en-US%22%3ETry%20using%20countifs%20function.%3CBR%20%2F%3E%3DCountifs(criteria1%20range%2Ccriteria1%2Ccriteria2%20range%2Ccriteria2%2C.....)%3CBR%20%2F%3EP%2Fs%20%3A%3CBR%20%2F%3E1.%20Criteria%20range%20will%20be%20the%20column%20where%20your%20data%20table%20for%20the%20variable%20located%3CBR%20%2F%3E2.%20Criteria%20will%20be%20the%20variable%20u%20looking%20for%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1516567%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Count%20instances%20of%20a%20variable%20within%20another%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1516567%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F723989%22%20target%3D%22_blank%22%3E%40ljoseph888%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPerhaps%20you%20may%20give%20bit%20more%20details.%20It%20will%20be%20like%3C%2FP%3E%0A%3CP%3EPerson1%20March%205%3C%2FP%3E%0A%3CP%3EPerson1%20April%204%3C%2FP%3E%0A%3CP%3EPerson1%20May%206%3C%2FP%3E%0A%3CP%3EPerson2%20June%202%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20mean%20we%20may%20generate%20the%20list%20of%20persons%20and%20additionally%20the%20list%20of%20months%20for%20each%20person%20(all%20of%20them%20are%20different).%20Or%20list%20of%20months%20is%20predefined%20and%20we%20just%20count%20zero%20if%20nothing%20for%20the%20concrete%20person%20in%20some%20months.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1517261%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Count%20instances%20of%20a%20variable%20within%20another%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1517261%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20Sergei%2C%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20looking%20to%20pick%20up%20another%20variable%20in%20the%20output%20that%20is%20uniquely%20associated%20with%20the%20person.%26nbsp%3B%20So%20each%20person%20has%20another%3A%3C%2FP%3E%3CP%3EInput%3A%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22ljoseph888_0-1594573057196.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F204830i3BEC60B3704FA871%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22ljoseph888_0-1594573057196.png%22%20alt%3D%22ljoseph888_0-1594573057196.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EOutput%3A%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22ljoseph888_1-1594573098772.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F204831i67207F65AFF240FF%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22ljoseph888_1-1594573098772.png%22%20alt%3D%22ljoseph888_1-1594573098772.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EActually%2C%20there%20are%20a%20few%20variables%20unique%20to%20each%20person%20I'd%20like%20to%20pick%20up%20in%20the%20output.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%2C%20I'm%20trying%20to%20decode%20the%20AGGREGATE%20function%20you%20originally%20sent%2C%20so%20that%20I%20actually%20understand%20it%20and%20can%20modify%20and%20apply%20it%20in%20other%20situations%20(want%20to%20learn%20to%20fish%20rather%20than%20just%20eat%20the%20fish%2C%20although%20eating%20the%20fish%20was%20very%20helpful%20%3A-)).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere%20is%20the%20AGGREGATE%20command%20you%20wrote%3A%26nbsp%3B%20(I%20understand%20the%20IFERROR)%3C%2FP%3E%3CP%3E%3CSPAN%3EAGGREGATE(14%2C6%2C1%2F(%24B%242%3A%24B%2410%3DE2)*COUNTIFS(%24B%242%3A%24B%2410%2C%24B%242%3A%24B%2410%2C%24C%242%3A%24C%2410%2C%24C%242%3A%24C%2410)%2C1)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EA%20few%20questions%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EI%20understand%20that%20the%20four%20parameters%20passed%20to%20AGGREGATE%20are%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E14%20(LARGE%20function)%20(why%20large%20vs%20count%3F)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E6%20(ignore%20errors)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E1%2F(%24B%242%3A%20.%20.%20.%20.%20.%20%24C%2410).%20---%20array%20over%20which%20to%20aggregate%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E1%20--%20I%20am%20assuming%20this%20is%20the%20second%20parameter%20of%20the%20large%20function%2C%20to%20return%20the%20largest%20value%3F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EI%20am%20really%20confused%20on%20the%20third%20line.%26nbsp%3B%20I%20don't%20understand%20the%201%2F%20(is%20that%20a%20division%20sign%3F).%26nbsp%3B%20I%20figure%20the%20(%24B%242%3A%24B%2410%3DE2)%20is%20aggregating%20unique%20entries%20in%20column%20B%20and%20putting%20the%20output%20starting%20at%20E2.%26nbsp%3B%20Not%20sure%20what%20function%20*%20has%2C%20I%20am%20assuming%20aggregate%20each%20unique%20entry%20in%20B%20by%20countifs%2C%20but%20I%20am%20confused%20that%20there%20is%20no%20criterion%20in%20the%20arguments%20for%20the%20countifs%3F%26nbsp%3B%20How%20does%20it%20know%20to%20count%20the%20%23As.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3ESorry%20to%20be%20a%20bother%2C%20but%20any%20light%20you%20can%20shed%20on%20this%20would%20be%20helpful.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EThanks!%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1517334%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Count%20instances%20of%20a%20variable%20within%20another%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1517334%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F723989%22%20target%3D%22_blank%22%3E%40ljoseph888%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20I%20understand%20your%20sample%20correctly%2C%20combination%20of%20the%20person%20name%20and%20Var%20A%20is%20always%20the%20same.%20Other%20words%2C%20if%20name%20is%26nbsp%3B%3CSTRONG%3ESue%3C%2FSTRONG%3E%20when%20Var%20A%20is%20always%20%3CSTRONG%3Ez%3C%2FSTRONG%3E%2C%20it%20can't%20be%20another%20value%2C%20i.e.%20%3CSTRONG%3Ex%3C%2FSTRONG%3E.%3C%2FP%3E%0A%3CP%3EIf%20so%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20525px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F204839iD5B352F21545F66C%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3Ein%20O3%20you%20may%20generate%20the%20list%20of%20such%20combinations%20by%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DUNIQUE(%24K%243%3A%24L%2410)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EAnd%20I'm%20not%20sure%20you'd%20like%20to%20count%20A%2C%20or%20B%2C%20or%20return%20the%20largest%20of%20above.%3C%2FP%3E%0A%3CP%3EIf%20count%20A%20for%20each%20person%20the%20simple%20COUNTIFS%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DCOUNTIFS(%24K%243%3A%24K%2410%2CUNIQUE(%24K%243%3A%24K%2410)%2C%24M%243%3A%24M%2410%2C%22A%22)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3Eand%20the%20same%20to%20count%20Bs.%20If%20largest%20of%20above%2C%20we%20use%20AGGREGATE%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DIFERROR(%0A%20AGGREGATE(14%2C6%2C%0A%20%20%20%201%2F(%24K%243%3A%24K%2410%3DO3)*%0A%20%20%20%20%20%20%20COUNTIFS(%24K%243%3A%24K%2410%2C%24K%243%3A%24K%2410%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%24M%243%3A%24M%2410%2C%24M%243%3A%24M%2410)%0A%20%20%2C1)%2C%0A%22%22)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EAGGREGATE%20returns%20first%20(4th%20parameter%20%3D%201)%20largest%20(1st%20parameter%20%3D%2014)%20from%20the%20array%20(3rd%20parameter)%20ignoring%20all%20errors%20(2nd%20parameter%20%3D%206).%3C%2FP%3E%0A%3CP%3EIn%20the%20array%20the%26nbsp%3B1%2F(%24K%243%3A%24K%2410%3DO3)%20is%20the%20filter.%20Second%20part%20returns%20TRUE%20or%20FALSE%20for%20each%20name%20of%20the%20range%20if%20it%20is%20equal%20or%20not%20to%20the%20value%20in%20O3.%20Since%20in%20arithmetic%20operations%26nbsp%3BTRUE%20and%20FALSE%20are%20equivalent%20of%201%20and%200%2C%20dividing%201%20on%20them%20we%20have%20an%20array%20of%201%3As%20or%20errors%20depends%20on%20name%20is%20match%20or%20not.%3C%2FP%3E%0A%3CP%3EThis%20array%20we%20multiply%20on%20an%20array%20returned%20by%20COUNTIFS()%20which%20counts%20number%20of%20each%20record%20person%2FVar%20A%20in%20the%20source.%20Multiplying%20on%20filter%20we%20have%20such%20array%20only%20for%20the%20person%20in%20O3%20and%20finally%20take%20largest%20value%20from%20that%20array.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1517669%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Count%20instances%20of%20a%20variable%20within%20another%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1517669%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%2C%20again%2C%20Sergei!%26nbsp%3B%20This%20is%20very%20helpful.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1518085%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20Count%20instances%20of%20a%20variable%20within%20another%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1518085%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F723989%22%20target%3D%22_blank%22%3E%40ljoseph888%3C%2FA%3E%26nbsp%3B%2C%20you%20are%20welcome%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

Complicated to explain . . . but I am trying to take a data set that looks something like this, with varying number of entries per person:

 

1.    person 1              A

2.    person 1              A

3.    person 1              B

4.    person 2              A

5.    person 2              B

6.   person 3               A

7.  person 3                A

8.  person 3                A

9.  person 3                A

 

And collapse it (or make a new data set) that has one line per person, with the number of As (and/or Bs)

                                #As

1.   Person 1              2

2.   Person 2              1

3.   Person 3:             4

 

Can Excel do this?  If so, can someone advise?

 

Thanks!

8 Replies
Highlighted
Best Response confirmed by ljoseph888 (New Contributor)
Solution

@ljoseph888 

For such sample

image.png

One variant:

In E2

=UNIQUE($B$2:$B$10)

in F2

=IFERROR(AGGREGATE(14,6,1/($B$2:$B$10=E2)*COUNTIFS($B$2:$B$10,$B$2:$B$10,$C$2:$C$10,$C$2:$C$10),1),"")

and drag it down.

 

Another variant - Power Query as in attached file.

Highlighted

@Sergei Baklan 

Follow up question (sorry, but you were so helpful!)

 

In my summary, I would like to include additional secondary variables.

 

For example:

                         var a          Count

1.  Person 1        March.       2

2.  Person 2.       March        1

3.  Person 3       April            4

 

Trying to figure it out on my own . . . 

 

Thanks!

 

 

Highlighted
Try using countifs function.
=Countifs(criteria1 range,criteria1,criteria2 range,criteria2,.....)
P/s :
1. Criteria range will be the column where your data table for the variable located
2. Criteria will be the variable u looking for
Highlighted

@ljoseph888 

Perhaps you may give bit more details. It will be like

Person1 March 5

Person1 April 4

Person1 May 6

Person2 June 2

 

I mean we may generate the list of persons and additionally the list of months for each person (all of them are different). Or list of months is predefined and we just count zero if nothing for the concrete person in some months.

Highlighted

@Sergei Baklan 

 

Hi Sergei, 

 

Thanks!

 

I'm looking to pick up another variable in the output that is uniquely associated with the person.  So each person has another:

Input:

ljoseph888_0-1594573057196.png

Output:

ljoseph888_1-1594573098772.png

 

Actually, there are a few variables unique to each person I'd like to pick up in the output.

 

Also, I'm trying to decode the AGGREGATE function you originally sent, so that I actually understand it and can modify and apply it in other situations (want to learn to fish rather than just eat the fish, although eating the fish was very helpful :-)).

 

Here is the AGGREGATE command you wrote:  (I understand the IFERROR)

AGGREGATE(14,6,1/($B$2:$B$10=E2)*COUNTIFS($B$2:$B$10,$B$2:$B$10,$C$2:$C$10,$C$2:$C$10),1)

 

A few questions:

I understand that the four parameters passed to AGGREGATE are:

14 (LARGE function) (why large vs count?)

6 (ignore errors)

1/($B$2: . . . . . $C$10). --- array over which to aggregate

1 -- I am assuming this is the second parameter of the large function, to return the largest value?

 

I am really confused on the third line.  I don't understand the 1/ (is that a division sign?).  I figure the ($B$2:$B$10=E2) is aggregating unique entries in column B and putting the output starting at E2.  Not sure what function * has, I am assuming aggregate each unique entry in B by countifs, but I am confused that there is no criterion in the arguments for the countifs?  How does it know to count the #As.

 

Sorry to be a bother, but any light you can shed on this would be helpful.

 

Thanks!

 

 

Highlighted

@ljoseph888 

If I understand your sample correctly, combination of the person name and Var A is always the same. Other words, if name is Sue when Var A is always z, it can't be another value, i.e. x.

If so

image.png

in O3 you may generate the list of such combinations by

=UNIQUE($K$3:$L$10)

And I'm not sure you'd like to count A, or B, or return the largest of above.

If count A for each person the simple COUNTIFS

=COUNTIFS($K$3:$K$10,UNIQUE($K$3:$K$10),$M$3:$M$10,"A")

and the same to count Bs. If largest of above, we use AGGREGATE

=IFERROR(
 AGGREGATE(14,6,
    1/($K$3:$K$10=O3)*
       COUNTIFS($K$3:$K$10,$K$3:$K$10,
                $M$3:$M$10,$M$3:$M$10)
  ,1),
"")

AGGREGATE returns first (4th parameter = 1) largest (1st parameter = 14) from the array (3rd parameter) ignoring all errors (2nd parameter = 6).

In the array the 1/($K$3:$K$10=O3) is the filter. Second part returns TRUE or FALSE for each name of the range if it is equal or not to the value in O3. Since in arithmetic operations TRUE and FALSE are equivalent of 1 and 0, dividing 1 on them we have an array of 1:s or errors depends on name is match or not.

This array we multiply on an array returned by COUNTIFS() which counts number of each record person/Var A in the source. Multiplying on filter we have such array only for the person in O3 and finally take largest value from that array.

Highlighted

@Sergei Baklan 

Thank you, again, Sergei!  This is very helpful.  

 

 

Highlighted