Forum Discussion

TomSinAA's avatar
TomSinAA
Helper IV
3 years ago
Solved

Count rows by ID in table

Is it possible to display the count of rows for each specific ID in a table for each ID.  So if my table has

ColorID
Blue1
Green1
Red1
Yellow2
Orange2
Purple2
Pink2

 Can I create an measure or use a dax expression to include the count of the colors for each ID as shown below

ColorIDCount of Colors
Blue13
Green13
Red13
Yellow24
Orange24
Purple24
Pink24
  • TomSinAA's avatar
    TomSinAA
    3 years ago

    Hi aniya Zhang

     

    I went with option 2 to add a column to the table.  It worked.  Thanks so much

     

    Tom

     

2 Replies

  • Hi, TomSinAA 

    According to your description, you want to "create an measure or use a dax expression to include the count of the colors for each ID".

    Here are teh steps you can refer to :
    My test data is the same as yours.

    [1]If you want to add a measure on the visual , you can click "New Measure" to create :

    Measure = var _id=  VALUES('Table'[ID])
    var _t = SELECTCOLUMNS(FILTER( ALLSELECTED('Table') ,'Table'[ID] in  _id) , "Color" , [Color])
    return
    COUNTROWS(_t)

    Then we can put the measure on the visual and we can meet your need:

    [2] If you want to add a calculated column in the table , you can click "New Column" and enter this:

    Column = var _id =  [ID]
    var _t = SELECTCOLUMNS(FILTER('Table','Table'[ID]=_id) , "Color" , [Color])
    return
    COUNTROWS(_t)

    Then we can get this result :

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

    • TomSinAA's avatar
      TomSinAA
      Helper IV

      Hi aniya Zhang

       

      I went with option 2 to add a column to the table.  It worked.  Thanks so much

       

      Tom