Hello, I would like to write a calculation using data in a table to know the number of distinct IDs which are there for each sector and company. My data is much larger than this example and I will have duplicate records (there are other columns which have different data in them).
The result would be:
Sector B Company 1 appears twice but for the same ID so that is considered as 1 whereas Sector C Company 2 appears twice with different IDs so this counts as 2.
In SQL, I would do this as
select sector, company, count(distinct ID) from table
group by sector, company
If that helps - this is what I really want to do. I have searched and tried options using SUMPRODUCT and COUNTIFS but I couldn't seem to make it work.
Thanks in advance
Id | Sector | Company |
123 | Sector A | Company 1 |
123 | Sector B | Company 1 |
234 | Sector A | Company 2 |
234 | Sector C | Company 2 |
234 | Sector A | Company 1 |
123 | Sector B | Company 1 |
567 | Sector C | Company 2 |
The result would be:
Sector | Company | Number |
Sector A | Company 1 | 2 |
Sector B | Company 1 | 1 |
Sector A | Company 2 | 1 |
Sector C | Company 2 | 2 |
Sector B Company 1 appears twice but for the same ID so that is considered as 1 whereas Sector C Company 2 appears twice with different IDs so this counts as 2.
In SQL, I would do this as
select sector, company, count(distinct ID) from table
group by sector, company
If that helps - this is what I really want to do. I have searched and tried options using SUMPRODUCT and COUNTIFS but I couldn't seem to make it work.
Thanks in advance