Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply

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 15
rsbin
Super User
Super User

@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,

I need to show the ProductID without the color

@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.

rsbin_0-1666032837894.png

 

This is a better sample dataset... I only added two rows, but shows the problem I am facing with the dax formula you shared above. 

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

@PowerBIUser349 ,

Are you now saying your Table includes duplicates?

Product ID Color Count
123 Red 1
124 Blue 1
123 Red 1
124 Blue 1

Do you want these duplicates counted or not?

Good question. And sorry for not explaining better. I still need it to return this:

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

 

Which means it would be a distinct count of Product ID, but showing the subtotal count for each color. 

@PowerBIUser349 ,

So, I think you are looking for a new Calculated Table.

Unfortunately, I have to sign off, but will try to look at it later this evening or tomorrow for you.

Kind Regards,

@PowerBIUser349 ,

Do not want to leave you hanging if this issue is still unresolved.  Would like to try to clean this up if need be.  I think the first step is to get this calculated column from my original response working for you.

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

If possible, please attach a sample pbix file and I can try to work with that.

Regards,

 

Nevermind... I don't have the option to attach files. See this link: https://drive.google.com/file/d/1kDUwCJccvUTnm-czvExzVi9t8YUXWyo4/view?usp=sharing

@PowerBIUser349 ,

Think I got it straightened out now.  My original reply was to create a Calculated Column.  You inadvertently created a Measure.  That is why it was not working the way I intended.

Please review the attached with my corrections.  I hope this now resolves the issue.

Best Regards,

I see. Unfortunately this doesn't work for my actual data... it works for this scenario, but my dataset is much more granular and this formula is counting every row in the table.  

I am still trying to figure it out. I attached a pbix file to the orignial post. Thank you for your help. 

Dang... my actual dataset is much more complex and I am not able to do that... the ProductID and Color was too simple. 

mangaus1111
Solution Sage
Solution Sage

Hi @PowerBIUser349 , I don' t understand what you mean by Group Count

See example. 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.