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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
CMDATA
Helper I
Helper I

Max Value of a count per group in Power Query

Hello,

 

I'm trying to get the max value of a count of items per group. Ideally this would be done in power query so I can have a table and map to it. I have another table that I can map to the group and I'd like to pull the most prevalent item per group into that table. 

 

Thank you in advance!!

 

Data Sample CSV file

 

Table from report to show counts per item: 

JobGroupItem IDCount of Item ID
210001.500          210001-01CC           00001          5
210001.500210001-01W000011
210001.500210001-03A000021
210001.500210001-26A000013
210001.500210001-26A000033
210001.500210001-26A0002614
210001.500210001-26A0003322
210001.500210001-28B000282
210001.500210001-31A000026
210001.500210001-31A000263
210001.500210001-31A0003190
210001.500210001-31A000322
210001.500210001-31A0003328
210001.500210001-31A100033126
210001.500210001-31B000013
210001.500210001-31B000021
210001.500210001-31B0003135
210001.500210001-31B000337
210001.500210001-31B100033123
210001.500210001-31C000317
210001.500210001-31E000011
210001.500210001-33A000022
210001.500210001-33A000032
210001.500210001-33A000093
210001.500210001-33A000261
210001.500210001-33A0003333
210001.500210001-99A000015
210001.500210001-99A000021
210001.500210001-99A000051
210001.500210001-99A000263
210001.500210001-99A000282
210001.500210001-99A0003248

 

Desired Result: 

JobGroupItem ID

Count of Item ID

(Shown for reference, not needed in the final table)

210001.500            210001-01CC          00001         5
210001.500210001-01W000011
210001.500210001-03A000021
210001.500210001-26A0003322
210001.500210001-28B000282
210001.500210001-31A0003190
210001.500210001-31A100033126
210001.500210001-31B0003135
210001.500210001-31B100033123
210001.500210001-31C000317
210001.500210001-31E000011
210001.500210001-33A0003333
210001.500210001-99A0003248
1 ACCEPTED SOLUTION
CMDATA
Helper I
Helper I

Hello, 

 

After I posted this I found a site that showed how to use multiple in group bys and then pull the data out. So I did:

1. Group by to get the columns I wanted with the counts of the groups

2. Group by to get the Max Count of each group along with the All Rows option. 

3. Custom Column using Table.Max to get the records associated with the Max count per group. 

4. Expanded the record column to get the value in the detail record that I wanted (the Item ID). 

 

Thank you all for your replies! 

View solution in original post

4 REPLIES 4
CMDATA
Helper I
Helper I

Hello, 

 

After I posted this I found a site that showed how to use multiple in group bys and then pull the data out. So I did:

1. Group by to get the columns I wanted with the counts of the groups

2. Group by to get the Max Count of each group along with the All Rows option. 

3. Custom Column using Table.Max to get the records associated with the Max count per group. 

4. Expanded the record column to get the value in the detail record that I wanted (the Item ID). 

 

Thank you all for your replies! 

Hi, @CMDATA 

Glad to hear that you have found a solution by yourself and thank you for sharing your experience. Would you like to mark your own reply as a solution so that others can learn from it too?

Thanks in advance!

 

Best Regards,

Community Support Team _Robert Qin

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

v-robertq-msft
Community Support
Community Support

Hi, @CMDATA 

According to your description and picture, you want to get a table that contains the most count of ID group by [group], I think you can also achieve this using a calculated table, which can also be mapped. You can take a look at my method and find if it’s useful:

  1. Create a measure:
Rank =

RANKX(FILTER(ALL('Table'),[Group]=MAX([Group])),CALCULATE(MAX('Table'[Count of Item ID])),,DESC,Dense)
  1. Create a calculated table:
Table 2 =

FILTER('Table',[Rank]=1)

 

And you can get what you want, like this:

v-robertq-msft_0-1608881269969.png

 

You can download my test pbix file here

 

Best Regards,

Community Support Team _Robert Qin

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

DataInsights
Super User
Super User

@CMDATA,

 

You can use the Group By wizard in Power Query. Right-click the column [Count of Item ID] and select Group By. Configure as follows:

 

DataInsights_0-1608823492694.png

Result:

 

DataInsights_1-1608823502553.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.