Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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
Solved! Go to Solution.
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
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
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:
Once you get your grouped dataset, you can use Top 10 in your report.
Let me know if this is helpful.
Thanks.
User | Count |
---|---|
25 | |
12 | |
8 | |
6 | |
6 |
User | Count |
---|---|
26 | |
12 | |
12 | |
10 | |
6 |