locked
DAX: COUNTROWS of unique values RRS feed

  • Question

  • Hey all, 

    Sorry, simple question here.  But I'm trying to calculate the number of rows for each unique ID.  I want to create the Count column.

    But I'm not sure if I need to use CALCULATE function, and/or where I put the FILTER function, too.  Thoughts?

    ID Color Count
    282 Red 2
    282 Green 2
    9991 Black 3
    9991 Red 3
    9991 Black 3
    884 Green 1

    Thanks, 

    ~UG

    Wednesday, January 20, 2016 9:22 PM

Answers

  • Hi UG,

    You could try something like this:

    MyCount = 
    CALCULATE(
      COUNTROWS(TableName), 
      ALLEXCEPT(TableName, TableName[ID])
    )


    Regards,

    Michael Amadi

    Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to vote it as helpful :)

    Website: http://www.nimblelearn.com, Twitter: @nimblelearn

    • Proposed as answer by Darren GosbellMVP Wednesday, January 20, 2016 9:59 PM
    • Marked as answer by undergrads1 Wednesday, January 20, 2016 10:28 PM
    Wednesday, January 20, 2016 9:53 PM

All replies

  • Hi UG,

    You could try something like this:

    MyCount = 
    CALCULATE(
      COUNTROWS(TableName), 
      ALLEXCEPT(TableName, TableName[ID])
    )


    Regards,

    Michael Amadi

    Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to vote it as helpful :)

    Website: http://www.nimblelearn.com, Twitter: @nimblelearn

    • Proposed as answer by Darren GosbellMVP Wednesday, January 20, 2016 9:59 PM
    • Marked as answer by undergrads1 Wednesday, January 20, 2016 10:28 PM
    Wednesday, January 20, 2016 9:53 PM
  • Perfect!!  Thank you again, Michael!

    ~UG

    Wednesday, January 20, 2016 10:28 PM