Forum Discussion
Find the top 1 for rows
Hi everyone,
I'm struggling with the following and was hoping someone would be able to help.
I have the following example table of my dataset:
| Client | Employee | Interactions |
| Client 1 | Lisa | 7 |
| Client 1 | John | 20 |
| Client 2 | Lisa | 9 |
| Client 2 | John | 14 |
| Client 2 | Sean | 33 |
and I need a Dax query that will return a table that will show the top 1 employee per client based on maximum interactions. For example in the table below:
| Client | Employee | Interactions |
| Client 1 | John | 20 |
| Client 2 | Sean | 33 |
Try the following :
Top Employee by Client = SUMMARIZE( Emp, Emp[Client], "Top Employee", CALCULATE(MAXX( FILTER( Emp, Emp[Interactions] = MAX(Emp[Interactions]) ), Emp[Employee] )), "Max Interactions", MAX(Emp[Interactions]) )- Anonymous2 years ago
Hi Daffness ,
Here some steps that I want to share, you can check them if they suitable for your requirement.
Here is my test data:
Create two measures
TopEmployeeByInteractions = VAR TopInteractionPerClient = CALCULATETABLE( TOPN( 1, SUMMARIZE( 'Table', 'Table'[Client], 'Table'[Employee], "TotalInteractions", SUM('Table'[Interactions]) ), [TotalInteractions], DESC ), ALLEXCEPT('Table', 'Table'[Client]) ) RETURN MAXX(TopInteractionPerClient, [Employee])TopInterations = VAR _t = SUMMARIZE('Table', 'Table'[Client], "Top",[TopEmployeeByInteractions], "Interations",MAX('Table'[Interactions]) ) RETURN MAXX(_t,[Interations])Final output
Best regards,
Albert He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
3 Replies
- AmiraBedhSuper User
Try the following :
Top Employee by Client = SUMMARIZE( Emp, Emp[Client], "Top Employee", CALCULATE(MAXX( FILTER( Emp, Emp[Interactions] = MAX(Emp[Interactions]) ), Emp[Employee] )), "Max Interactions", MAX(Emp[Interactions]) )- DaffnessNew Member
- AnonymousNot applicable
Hi Daffness ,
Here some steps that I want to share, you can check them if they suitable for your requirement.
Here is my test data:
Create two measures
TopEmployeeByInteractions = VAR TopInteractionPerClient = CALCULATETABLE( TOPN( 1, SUMMARIZE( 'Table', 'Table'[Client], 'Table'[Employee], "TotalInteractions", SUM('Table'[Interactions]) ), [TotalInteractions], DESC ), ALLEXCEPT('Table', 'Table'[Client]) ) RETURN MAXX(TopInteractionPerClient, [Employee])TopInterations = VAR _t = SUMMARIZE('Table', 'Table'[Client], "Top",[TopEmployeeByInteractions], "Interations",MAX('Table'[Interactions]) ) RETURN MAXX(_t,[Interations])Final output
Best regards,
Albert He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly