counting unique values where those value match a criteria

Aeropars

New Member
Joined
May 23, 2019
Messages
7
Hi all,

I'm having a bit of a brain explosion over this so should I would register for some help.

I have a spreadsheet which has 3 columns. Column A contains a list of computer names, Column B contains a list of services, column C contains the status of the service.

What I want is to count all the unique values from column A where column C has an entry of 'stopped'. The idea is that I can use this for reporting the number of devices which have any service in a stopped state. an example of the table is as follows:

ComputerServiceState
PC01Service 1Running
PC01Service 2Stopped
PC01Service 3Stopped
PC02Service 1Running
PC02Service 2Running
PC02Service 3Running
PC03Service 1Stopped
PC03Service 2Running
PC03Service 3Running

<colgroup><col><col span="2"></colgroup><tbody>
</tbody>
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
like this?

ComputerServiceStateComputerStateCount
PC01Service 1RunningPC01Stopped
2​
PC01Service 2StoppedPC03Stopped
1​
PC01Service 3Stopped
PC02Service 1Running
PC02Service 2Running
PC02Service 3Running
PC03Service 1Stopped
PC03Service 2Running
PC03Service 3Running
 
Upvote 0
like this?

ComputerServiceStateComputerStateCount
PC01Service 1RunningPC01Stopped
2​
PC01Service 2StoppedPC03Stopped
1​
PC01Service 3Stopped
PC02Service 1Running
PC02Service 2Running
PC02Service 3Running
PC03Service 1Stopped
PC03Service 2Running
PC03Service 3Running

we don't know much if you don't show the formula
 
Upvote 0
I think Sandy is just querying if that is the format that the op would like to see. If so then a SUMPRODUCT will do, linking up to the Computer and the State. Given the data in the example then something like this for the count of PC01:

=SUMPRODUCT(($A$2:$A$10="PC01")*($C$2:$C$10="Stopped"))

If this is the format required I would copy column A to begin with and paste in to say, column E, then use the built in remove duplicates tool (Data tab -> Remove Duplicates) to get a unique list, then link the SUMPRODUCT formula to the cell of the PC number and drag it down.
 
Last edited:
Upvote 0
Thanks for the reply.

No, all I need for my reporting is to have a count of the total number of PCs where a service is stopped. So The formula i'm looking for is to give me a total number of PCs that have one or more services stopped. What those services are is irrelevant and it doesn't make a difference to my reporting whether a single service or all services are stopped. So all it would nee to to is give me a number of PCs with issues.

Hope that makes sense. Let me know if you have any other questions
 
Upvote 0
like this?

ComputerServiceStateStateCount
PC01Service 1RunningStopped
3​
PC01Service 2Stopped
PC01Service 3Stopped
PC02Service 1Running
PC02Service 2Running
PC02Service 3Running
PC03Service 1Stopped
PC03Service 2Running
PC03Service 3Running

Code:
[SIZE=1]// Table1
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Group = Table.Group(Source, {"State"}, {{"Count", each Table.RowCount(_), type number}}),
    Filter = Table.SelectRows(Group, each ([State] = "Stopped"))
in
    Filter[/SIZE]
 
Upvote 0
@AlanY

formula (?) doesn't matter if result is not like OP want so I need to know first if result is ok then I can post M-code
 
Upvote 0
Yes, that look to be what I am after.

I'm a little confused as to how that code works though. where do I put it?

Apologies if this is a bit of a basic question, I'm not THAT advanced with excel.
 
Upvote 0
If you want a standard Excel formula then use a COUNTIF function,

=COUNTIF(C2:C10,"Stopped")

will return how many PCs have the state "Stopped"
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,550
Members
449,088
Latest member
davidcom

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