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
EdEvetts
Helper II
Helper II

how do I summarize values in a table by category and show all categories with top value?

Hi all,

I would be grateful for any help anyone can give me on this problem, which has been driving me mad over the last 24 hours. I am new to DAX and PBI and normally can work it out with the help of various useful sites, but this one has me stuck.

 

I have the data below in a single table (this is a selection of columns from that table) and I am trying to summarise the values by category and then show the top category for each team - as shown in the second table. 

 

TeamCategoryValue
AApples5
BPears7
AOranges4
CApples2
AApples2
AGrapes2
ABananas4
DApples6
CPears2
CPears1
BBananas3
BPears4
DBananas5

 

Result I am trying to achieve

 

 

TeamCategoryValue
AApples7
BPears11
CPears3
DApples6

 

I have looked at TopN, Max, SumX but cant work it out and nearly got to the point of just summarising the data in another table, but really hope its possible to produce the result I need without doing that. As I say would really appreciate any help

 

thanks Ed

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@EdEvetts

i know there are other ways to achieve it but ,can you try this below

1. Add a new table to summarize the Value by team and category 

 Aggregate = SUMMARIZE(Data,Data[Team],Data[Category],"Value",SUM(Data[Value])) 


2. Add 2 below Measures 

TotalValue = SUM([Value])
Rank = RANKX(All('Aggregate'[Category]),[TotalValue],,,Dense)


3.Go to Report and drag and Drop the Table and Add Team,Category and Value to it

4. Add the Rank to FIlter and filter to 1. This is the trick we can use filter the top ranked value

 

we are done. the below is your result 🙂

 

Summarize.PNG

View solution in original post

10 REPLIES 10
Sean
Community Champion
Community Champion

If all you are trying to do is this table - No need for any DAX - just create a Matrix as in the picture...

MatirxSample.png

Thanks for your help Sean, I was looking to take what you have there and create a table that would then just show the top category, so A would be Apples 7, B Pears 11, C Pears 3 and D Apples 6. Would there be any way of doing that ?

 

thanks Ed

Sean
Community Champion
Community Champion

I don't use RANK and TOPN that much so this is not done yet... (the total values are still overall totals)

TOPN.png

I gotta go... In the meantime someone may have a better solution...

thanks so much for your help and time Sean its really appreciated, I'll try these out, 


Ed

Anonymous
Not applicable

@EdEvetts

i know there are other ways to achieve it but ,can you try this below

1. Add a new table to summarize the Value by team and category 

 Aggregate = SUMMARIZE(Data,Data[Team],Data[Category],"Value",SUM(Data[Value])) 


2. Add 2 below Measures 

TotalValue = SUM([Value])
Rank = RANKX(All('Aggregate'[Category]),[TotalValue],,,Dense)


3.Go to Report and drag and Drop the Table and Add Team,Category and Value to it

4. Add the Rank to FIlter and filter to 1. This is the trick we can use filter the top ranked value

 

we are done. the below is your result 🙂

 

Summarize.PNG

thanks Sarr, really appreciated, i'll try this out 

 

@Anonymous and it worked a treat

 

thanks 

Ed

Sean
Community Champion
Community Champion

@EdEvetts @Anonymous's solution actually helps mine too

 

Just add my Rank Category Measure to the Visual Slicers and make => is 1 and here it is

(you can even show who the Top team is for that category if the Team's Best Category was not the best result in that category

such as teams C and D)

TOPN2.png

 

Sean
Community Champion
Community Champion

@EdEvetts You can actually use my solution in 2 ways (Top Category formula is slightly modified)

 

1 - To see each Team's Top Category and Value in that Category (and whether they were the best team in that Category)

2 - To see each Category's Top Team and Value (and whether that was the best category for that Team)

(when you have more categories than teams as in this case)

TOPN3.png

 

Thanks Sean, i hadnt thought of looking at it from category by team, gives another insight

 

thanks Ed

Sean
Community Champion
Community Champion

@OwenAuger Your answer to the singles/doubles games question - reminded me of the problem in this post.

 

In my solution - we had to use the Visual Level Filters - do you think we can accomplish this without Visual Level Filters?

 

Thanks!

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.