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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
JeanBean
Frequent Visitor

Max Count of Group then Top 5 of Max

Hi,

 

I am new to Power Bi and I need help with this. I need to display the top N categories with the max count of that group. I cant use rank because I need to find the max grouped by. I wrote what I need in code and what I hope to display on power BI.

 

I need it to first give me a total count of all category by open date (inner select), then I need to get the top N categories with the most count (couter select).

 

Ideal SQL:

select top 5 b.cat, b.max_res
from (
select a.Cat, max(result_count) as max_res
from ( select Cat, Open_dt, count([result number]) as result_count from [result] group by Cat, open_dt) a group by a.Cat) b

 

 

so far I have 

 

Total_Result = DISTINCTCOUNT([result number])

 

When ever I use the MAX() I get this argument: The MAX function only accepts a column reference as the argument number 1.

 

 

MAX_G = CALCULATE(MAX([Total_Result]), GROUPBY(Query1, Query1[Cat], Query1[Open_dt]))

 

 

Then for TopN I get this Issue: The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.

TOPn = topn(5, Query1, [MAX_G])

 

 

1 ACCEPTED SOLUTION
v-ljerr-msft
Employee
Employee

Hi @JeanBean,

 

Could you post your table structures(including table relationships) with some sample data and your expected result, so that we can better assist on the DAX formula needed? Smiley Happy

 

Regards

View solution in original post

1 REPLY 1
v-ljerr-msft
Employee
Employee

Hi @JeanBean,

 

Could you post your table structures(including table relationships) with some sample data and your expected result, so that we can better assist on the DAX formula needed? Smiley Happy

 

Regards

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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