Count Distinct Values

Greig

New Member
Joined
Jul 22, 2013
Messages
9
I have created a Power Pivot report from a data cube. It looks like:

Column A Column B Column C
Affirmed
Affirmed
Varied Affirmed Affirmed
Varied Affirmed Cancelled

I want to count how many times the word Affirmed appears in the report. I have tried various formulas without luck. I am using Excel 2010. Thanks Greig
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hey, few ways you could approach this:

- the 'simplest' is probably to create a calculated column in your table that uses the SEARCH() function to check for affirmed in each column and add 1s where it is the case to give you a count e.g.:

Code:
=
IFERROR (
    IF ( ISNUMBER ( SEARCH ( "Affirmed", [Column A] ) ), 1, 0 ),
    0
)
    + IFERROR (
        IF ( ISNUMBER ( SEARCH ( "Affirmed", [Column B] ) ), 1, 0 ),
        0
    )
    + IFERROR (
        IF ( ISNUMBER ( SEARCH ( "Affirmed", [Column C] ) ), 1, 0 ),
        0
    )

This isn't pretty and perhaps there is a more elegant way but it works! The way SEARCH() works in DAX is stupid as if it doesn't find the string it produces an error regardless of the ISNUMBER() so has to be wrapped in an IFERROR().

- the 'better' way is to do it in a measure. This won't be particularly clean as PowerPivot is 'column' based so you will need to do the calc for each column. A measure would look like this:

Code:
=
CALCULATE (
    COUNTROWS ( Table1 ),
    Table1[Column A]
        = "Affirmed"
)
    + CALCULATE (
        COUNTROWS ( Table1 ),
        Table1[Column B]
            = "Affirmed"
    )
    + CALCULATE (
        COUNTROWS ( Table1 ),
        Table1[Column C]
            = "Affirmed"
    )

Again this isn't going to win prizes for elegance but gets it done. Note this counts how many times the word appears not how many rows it appears in!
 
Upvote 0
Many thanks Jacob. Help is much appreciated. Greig

Hey, few ways you could approach this:

- the 'simplest' is probably to create a calculated column in your table that uses the SEARCH() function to check for affirmed in each column and add 1s where it is the case to give you a count e.g.:

Code:
=
IFERROR (
    IF ( ISNUMBER ( SEARCH ( "Affirmed", [Column A] ) ), 1, 0 ),
    0
)
    + IFERROR (
        IF ( ISNUMBER ( SEARCH ( "Affirmed", [Column B] ) ), 1, 0 ),
        0
    )
    + IFERROR (
        IF ( ISNUMBER ( SEARCH ( "Affirmed", [Column C] ) ), 1, 0 ),
        0
    )

This isn't pretty and perhaps there is a more elegant way but it works! The way SEARCH() works in DAX is stupid as if it doesn't find the string it produces an error regardless of the ISNUMBER() so has to be wrapped in an IFERROR().

- the 'better' way is to do it in a measure. This won't be particularly clean as PowerPivot is 'column' based so you will need to do the calc for each column. A measure would look like this:

Code:
=
CALCULATE (
    COUNTROWS ( Table1 ),
    Table1[Column A]
        = "Affirmed"
)
    + CALCULATE (
        COUNTROWS ( Table1 ),
        Table1[Column B]
            = "Affirmed"
    )
    + CALCULATE (
        COUNTROWS ( Table1 ),
        Table1[Column C]
            = "Affirmed"
    )

Again this isn't going to win prizes for elegance but gets it done. Note this counts how many times the word appears not how many rows it appears in!
 
Upvote 0
Can someone please tell me how to Count only the distinct values in column a? Example:

Name of Column A: Contact_ID

Values in Column A:
123456789
321456987
321456987
321456987
951236958
8896587
556987
556987
23258877
362569878
362569878

I only want excel to count that there are 7 - I want them to ignore the duplicates. this report has to show the dups, but only count the "people".

Please help
 
Upvote 0

Forum statistics

Threads
1,224,071
Messages
6,176,200
Members
452,714
Latest member
streamer1234

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