Forum Discussion

PowerBIUser349's avatar
3 years ago

Count by Group

Hey Everyone, I know this is going to be simple for someone experienced in PBI. I am still getting use to specific functions and could use some help. Here is a sample dataset:

Product IDColorCount
123Red1
124Blue1
125Blue1
126Red1
127Yellow1
128Red1
129Yellow1
130Red1
131Blue1

 

Then I am counting by each color group (My dax is currently doing this fine):

ColorCount
Red4
Blue3
Yellow2

 

I need help getting this output:

Product IDGroup Count
1234
1243
1253
1264
1272
1284
1292
1304
1313

15 Replies

  • rsbin's avatar
    rsbin
    Community Champion

    PowerBIUser349 ,

    I believe this Calculated Column should get you what you need:

    ColorCount = CALCULATE( COUNTA([Color]), ALLEXCEPT( 'Product', 'Product'[Color] ))

    Product IDColorCountColorCount

    123 Red 1 4
    124 Blue 1 3
    125 Blue 1 3
    126 Red 1 4
    127 Yellow 1 2
    128 Red 1 4
    129 Yellow 1 2
    130 Red 1 4
    131 Blue 1 3

    Regards,

      • rsbin's avatar
        rsbin
        Community Champion

        PowerBIUser349 ,

        Once you have your Calculated Column in the data model, you can create any Visual that you want. 

        For a simple Table Visual, simply use your ProductID and ColorCount columns.  You don't need to show the Color field in your visual.