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
Anonymous
Not applicable

Custom column by dividing a column depending on a field [M-query]

Hi dear rescuers, 

 

I'm trying to divide a column based on another field. 

I would like to divide the rating field by the count of the subject to the corresponding category.  For example, the rating for science is 300.  I merged the subject column to category and rating, so it created multiple rows of 300. I would like to achieve the last column. where the original value of science is divided into equal parts by the count of the corresponding subject. 

 

Thanks in advance for your help 🙂 

 

Capture.PNG

1 ACCEPTED SOLUTION
drewlewis15
Solution Specialist
Solution Specialist

 

It might be eaiser to solve this using DAX, but the steps below should solve your issue using M.

 

Group by Category and choose to aggregate by "Count" and "All Rows"

step1.png

Then expand all rows (excluding Category), and you should end up with the following:

step2.png

 

You can now create a custom column dividing your sum column by your count column.

End Result:

step3.png

View solution in original post

2 REPLIES 2
drewlewis15
Solution Specialist
Solution Specialist

 

It might be eaiser to solve this using DAX, but the steps below should solve your issue using M.

 

Group by Category and choose to aggregate by "Count" and "All Rows"

step1.png

Then expand all rows (excluding Category), and you should end up with the following:

step2.png

 

You can now create a custom column dividing your sum column by your count column.

End Result:

step3.png

Anonymous
Not applicable

Thanks a lot. It worked 🙂

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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