Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Count distinct values based on another column

Hello experts,

I'm just starting with Power BI and i cant get over one thing. I have a table with columns "Name" "Issue" "Status"
It looks like this:

 

NameIssueStatus

Name1

Test1Open
Name1Test2Open
Name1Test3Closed
Name2Test4Closed
Name2Test5Closed
Name2Test6Closed
Name2Test7Open
Name3Test8Closed

 

And i want a summary for each value in the Name column with count of the values in Status Column
Result should look like this:

NameOpenClosed
Name121
Name213
Name301


Any help there? I'm was searching through community posts but nothing worked for me

  • Hi Anonymous ,

     

    You need 2 measures as below:

    Open = CALCULATE(COUNT('Table'[Status])+0,ALLEXCEPT('Table','Table'[Name]),'Table'[Status]="Open")
    close = CALCULATE(COUNT('Table'[Status])+0,ALLEXCEPT('Table','Table'[Name]),'Table'[Status]="Closed")

    Finally you will see:

    Or  you can  create a new table,using a dax expression as below:

     

     

    Table 2 =
    SUMMARIZE (
        'Table',
        'Table'[Name],
        "Open", CALCULATE (
            COUNT ( 'Table'[Status] ) + 0,
            ALLEXCEPT ( 'Table', 'Table'[Name] ),
            'Table'[Status] = "Open"
        ),
        "Close", CALCULATE (
            COUNT ( 'Table'[Status] ) + 0,
            ALLEXCEPT ( 'Table', 'Table'[Name] ),
            'Table'[Status] = "Closed"
        )
    )

     

     

    Finally,you will see:

    For the related .pbix file,pls click here.

     

    Best Regards,
    Kelly

4 Replies

  • Try

    Open = calculate(count(table[issue]),	table[Status]="Open")
    Closed calculate(count(table[issue]),	table[Status]="Closed")
    issue =count(table[issue])

     

    The first two measures you can use in table or matrix with name in row.

    The third one you can use in matrix name in row and issue in a col

     

    Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.
    In case it does not help, please provide additional information and mark me with @

    Thanks. My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP, HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
    Connect on Linkedin

     

     

     

     

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      It's not working i am getting this result:

      NameOpenClosed
      Name135
      Name235
      Name335
  • v-kelly-msft's avatar
    v-kelly-msft
    Community Support

    Hi Anonymous ,

     

    You need 2 measures as below:

    Open = CALCULATE(COUNT('Table'[Status])+0,ALLEXCEPT('Table','Table'[Name]),'Table'[Status]="Open")
    close = CALCULATE(COUNT('Table'[Status])+0,ALLEXCEPT('Table','Table'[Name]),'Table'[Status]="Closed")

    Finally you will see:

    Or  you can  create a new table,using a dax expression as below:

     

     

    Table 2 =
    SUMMARIZE (
        'Table',
        'Table'[Name],
        "Open", CALCULATE (
            COUNT ( 'Table'[Status] ) + 0,
            ALLEXCEPT ( 'Table', 'Table'[Name] ),
            'Table'[Status] = "Open"
        ),
        "Close", CALCULATE (
            COUNT ( 'Table'[Status] ) + 0,
            ALLEXCEPT ( 'Table', 'Table'[Name] ),
            'Table'[Status] = "Closed"
        )
    )

     

     

    Finally,you will see:

    For the related .pbix file,pls click here.

     

    Best Regards,
    Kelly

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi v-kelly-msft,

      It worked, thanks for help

       

      Best Regards,
      ksusser