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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
naveen73
Helper III
Helper III

Generate column with count of values

Hi all,

 

I am working with a dataset and merging another set and applying filters.

At some point I am getting the “Value” column (see screenshot). However, the values are a sum of each of the “Product Code”. This mean I need to have a column so that I it shows the number of instances the “Product Code” appears i.e. “Generate Column”.  Then I can make a column to the right of it: “My Column”.

 

Can you help me with generating “Generate Column”, please?

Strangely enough I am not able to find the answer to this question not on the Internet.

 

naveen73_0-1700436470104.png

 

Thanks,

 

Naveen

6 REPLIES 6
j_ocean
Helper V
Helper V

You could always reference the table, group-by to get the count, and merge it back in.

hmonty
Frequent Visitor

Hi, I also struggled to find any help online with this issue.
My approch has been (in power query), to select the column I want to count, and go to group by, click on the advanced tab and give the new column a name, select count rows, then add another column underneath and select all rows. 

1.jpg

 

 

 

 

 

 

when you click ok, you should get the column you wanted to group by, a count of the values and a column with a table you can expand2.jpg
expanding return your orginal columns, plus the count of selected values in a new column.

 

I hope this helps with your query. 🙂

naveen73
Helper III
Helper III

Hi @wdx223_Daniel 

Thanks for your efforts. I was looking for a solution in M language. Would you (anybody) be able to help me with in M. Perhaps it is technically not possible in M?

 

Thanks,

 

Naveen

=Table.Combine(Table.Group(YourTableName,"Product Code",{"n",each let a=Table.RowCount(_) in Table.AddColumn(_,"Custom",each [Value]/a)})[n])

Right Click on the Column(s) You want to group by --> Group By --> Operation --> Count Rows

wdx223_Daniel
Super User
Super User

=DIVIDE(SUM(Table[Volume]),CALCULATE(SUM(Table[Volume]),ALLEXCEPT(Table,Table[Product Code])))

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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