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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

DAX function to count rows, Group by Column and divide by total count of rows

Dax function for the below steps from table AAA

  1. Count the number of rows in column “coldef” using group by condition. This column has data type as Text
  2. Count the total rows in column  “coldef” which has data type as text
  3. Divide step 1 by step 2
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

Please try:

Count of Column = COUNTROWS('Table')

- B% DAX = 
VAR allCount = CALCULATE(COUNTROWS('Table'),ALL('Table'))
RETURN
DIVIDE([Count of Column],allCount)

 

Once created, if you want to display percentages without decimals, you can check "%" in the Measure tool tab and then select the number of decimals to be followed by zero.

vhuijieymsft_0-1709794303442.png

 

If you use the Format function, it will default to two decimal places.

- B% DAX = 
VAR allCount = CALCULATE(COUNTROWS('Table'),ALL('Table'))
RETURN
FORMAT(DIVIDE([Count of Column],allCount), "Percent")

 

Drag the created measures to the report page for display, the page effect is shown below:

vhuijieymsft_1-1709794303447.png

 

The pbix file is attached.

 

If you have any other questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Thanks much for helping on this. Let me elaborate my question clearly. 

Source Table
Column - A
(TEXT)
Column - B
(TEXT)
FurnitureA01234
FurnitureA12345
AccessoriesC24564
AccessoriesC22335
AccessoriesD57845
AccessoriesD65894
AccessoriesE55882
EquipmentK98562
EquipmentK85857
EquipmentK22335
EquipmentL65875
EquipmentL78548
EquipmentL12548

 

Required Output
Column - A
(TEXT)
Count of Column - B% DAX
Furniture215%
Accessories538%
Equipment646%
Total13100%
Anonymous
Not applicable

Hi @Anonymous ,

 

Please try:

Count of Column = COUNTROWS('Table')

- B% DAX = 
VAR allCount = CALCULATE(COUNTROWS('Table'),ALL('Table'))
RETURN
DIVIDE([Count of Column],allCount)

 

Once created, if you want to display percentages without decimals, you can check "%" in the Measure tool tab and then select the number of decimals to be followed by zero.

vhuijieymsft_0-1709794303442.png

 

If you use the Format function, it will default to two decimal places.

- B% DAX = 
VAR allCount = CALCULATE(COUNTROWS('Table'),ALL('Table'))
RETURN
FORMAT(DIVIDE([Count of Column],allCount), "Percent")

 

Drag the created measures to the report page for display, the page effect is shown below:

vhuijieymsft_1-1709794303447.png

 

The pbix file is attached.

 

If you have any other questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

Anonymous
Not applicable

Thanks a lot for your help. 

Anonymous
Not applicable

Thank you very much, Amit for your help. 

This still needs some modification as the expected result should be something as below:

Row 1 - 55/277

Row 2 - 40/277 ..........

 

Column 1Row Count (Grouped)Divide
A5520%
B4014%
C207%
D7828%
E62%
F7828%
 277100%
Anonymous
Not applicable

Hi @Anonymous ,

 

This is sample data:

vhuijieymsft_0-1709629797988.png

 

This is your expected result:

vhuijieymsft_1-1709629797990.png

 

Please try:

TotalColumn1 = CALCULATE(SUM('Table'[Row Count (Grouped)]),ALL('Table'))

Column = DIVIDE([Row Count (Grouped)],[TotalColumn1])

 

You can do it with a measure, but it defaults to two decimals when converted to a percentage, and total is wrong, so it is better to use a New column.

 

The pbix file is attached.

 

If you have any other questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

amitchandak
Super User
Super User

@Anonymous , Based on what I got. Try a measure like

 

Divide( Countrows(Summarize(Table, Table[Column]) ), countrows(Table) )

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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