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

GROUPBY with Count

Hi,

 

I'm new to DAX. In SQL Server I have this query that returns a simple group by:

 

SELECT DISTINCT item_name, count(item_name) AS Item_count
FROM [MYDATABASE].[dbo].[MYTABLE]
GROUP BY item_name
ORDER BY Item_count DESC

 

The reason I need this DAX is so I can get the top 10 using the TOPN function. I can't seem to get my head around this, I've tried the DAX GROUPBY but keep getting errors. Is there someone who can point me in the right direction?

 

Regards,

Raymond

1 ACCEPTED SOLUTION
Anonymous
Not applicable

GROUP BY in SQL is usually SUMMARIZE in DAX 🙂

 

SUMMARIZE('MYTABLE', [item_name], "item_count", COUNTROWS('MYTABLE'))

 

That will create a table with two columns (item_name and item_count). Use that as <table> in the TOPN function.

 

Best Regards

Ulf

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

GROUP BY in SQL is usually SUMMARIZE in DAX 🙂

 

SUMMARIZE('MYTABLE', [item_name], "item_count", COUNTROWS('MYTABLE'))

 

That will create a table with two columns (item_name and item_count). Use that as <table> in the TOPN function.

 

Best Regards

Ulf

Pragati11
Super User
Super User

Hi,

 

Rather than using GROUP BY as a DAX, you can use GROUP BY in Query Editor and achieve this. I have taken a sample data and attached screenshots in the order as follows:

 

GroupBy.png

Once you get your grouped dataset, you can use Top 10 in your report.

 

Let me know if this is helpful.

 

Thanks.

 

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

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.