Count Distinct Cells in Multiple Columns with Criteria

leefletcher

New Member
Joined
Mar 22, 2018
Messages
29
Office Version
  1. 2019
Platform
  1. Windows
I'm trying to count how many distinct items appear across multiple columns with a single criteria from another column. My ability to use the right words might be keeping me from finding a solution on the web.


CitiesRestaurant 1Unrelated informationRestaurant 3Unrelated Information
BostonMcDonaldsMainPopeyesDown
BostonBurger KingElmMcDonaldsUp
Los AngelesWendysNorthPizza HutWest
Los AngelesMcDonaldsSouthWendys
Los AngelesPizza HutOak

Desired result:

CityTotal RestaurantsDistinct Restaurants
Boston43
Los Angeles53

How do I count the distinct entries across multiple columns (skipping over columns with unrelated information)?
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Maybe this idea helps you solve your task.
For total restaurants, place the following formula in cell 'H2' (copy down)
Code:
=COUNTIFS($A$2:$A$6,G2,$B$2:$B$6,"<>"&"")+COUNTIFS($A$2:$A$6,G2,$D$2:$D$6,"<>"&"")

For distinct restaurants, add 'helper columns', eg 'K' and 'L'. You can hide these columns or place them on another sheet.

Place the following formula in cell 'K2' (copy down)
Code:
=IFERROR(IFERROR(INDEX($A$2:$B$6,ROW($K2)-ROW($K$1),COLUMN($A$2:$A$6)),INDEX($A$2:$D$6,ROW($K2)-ROW($K$1)-ROWS($A$2:$D$6),COLUMN($A$2:$A$6))),"")

Place the following formula in cell 'L2' (copy down)
Code:
=IF(IFERROR(INDEX($B$2:$B$6,ROWS(C1:$C$1)),IFERROR(INDEX($D$2:$D$6,ROWS(C1:$C$1)-ROWS($B$2:$B$6)),""))=0,"",IFERROR(INDEX($B$2:$B$6,ROWS(C1:$C$1)),IFERROR(INDEX($D$2:$D$6,ROWS(C1:$C$1)-ROWS($B$2:$B$6)),"")))

For a distinct restaurant, place the following ARRAY or "CSE formula" in cell 'I2'. You need to finish the formula with Ctrl+Shift+Enter, not just Enter. (copy down)
Code:
=COUNT(1/FREQUENCY(IF($K$1:$K$20=$G2,IF($L$1:$L$20<>"",MATCH($L$1:$L$20,$L$1:$L$20,0))),ROW($L$1:$L$20)-ROW($L$1)+1))

I hope you can do it, see the screenshot below
Untitled-1.png
 
Upvote 0
Thank you. I hadn't thought of the helper column. I'll give it a shot. Thanks, again.
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,120
Members
451,399
Latest member
alchavar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top