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
shivkonar
Frequent Visitor

DAX GROUPBY each group

Hi,

 

I have a table like below in Power BI:

Screen Shot 2018-09-06 at 14.05.44.png

 

I want a table which return MAX(Rate) for each group, along with the group i.e. a table like below:

Screen Shot 2018-09-06 at 14.07.05.png

 

How can I achieve this?

 

Thanks,

Shiv

1 ACCEPTED SOLUTION

Table 2 = 
VAR __tmpTable = SUMMARIZE('Table31',[Name],"__MaxRate",MAX('Table31'[Rate]))
RETURN
ADDCOLUMNS(__tmpTable,"__Day",MAXX(FILTER(ALL('Table31'),[Rate]=[__MaxRate]),[Day]))

Table31 is my base table.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

8 REPLIES 8
v-danhe-msft
Employee
Employee

Hi @shivkonar,

Could you please tell me if your problem has been solved? If it is, could you please mark the helpful replies as Answered?

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

I suggest you check out the URL below: 

https://stackoverflow.com/questions/46582767/groupby-and-aggregate-in-dax

one of the best to describe the GROUP BY and aggregation functions. 

Greg_Deckler
Super User
Super User

Maybe something like this:

 

Measure Rate = MAX([Rate])

Measure Day = 
MAXX(FILTER('Table',[Rate]=[Measure Rate]),[Day])

Put these two measures in a table viz with [Name].


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Why we can't use an expression like below: 

 

NewTable = CALCULATETABLE(Table1, GROUPBY(Table1, Table1[Day],Table1[Name], "maxrate", MAX(Table1[Rate])))

 

@Anonymous I get this error

"Function GROUPBY sclar expressions have to be Aggregation functions over CurrentGroup(). The expression of each Aggregation has to be either a constant or direct reference the columns in CurrentGroup()"

Anonymous
Not applicable

Yes, Exactly. I receive the same error. And I don't understand what is the probelm 

Table 2 = 
VAR __tmpTable = SUMMARIZE('Table31',[Name],"__MaxRate",MAX('Table31'[Rate]))
RETURN
ADDCOLUMNS(__tmpTable,"__Day",MAXX(FILTER(ALL('Table31'),[Rate]=[__MaxRate]),[Day]))

Table31 is my base table.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thanks @Greg_Deckler

 

Is it possible to get a calculated table?

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.