cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Sum of TOPN Columns

Hey everyone,

How do i SUM only the Top 10 values of a table?

I tried this:

 

Total SUM TOPN = CALCULATE([Total SUM], FILTER(Table, RANKX(ALL(Table[Name]), [Total SUM],,DESC) <= 10))

 

but it doesn't work. It gives me the total sum od all the rows.

Can someone tell me what am I doing wrong?

Thanks 🙂

2 ACCEPTED SOLUTIONS
Vvelarde
Community Champion
Community Champion

@Anonymous

 

You need  to group the categories to applied the aggregation.

 

One way is this:

 

 

Top2RL =
CALCULATE (
    SUM ( Table3[Value] ),
    TOPN (
        3,
        GROUPBY ( Table3, Table3[Category] ),
        CALCULATE ( SUM ( Table3[Value] ) )
    )
)



Lima - Peru

View solution in original post

Hi @Anonymous,

 

Great to hear the problem got resolved.Smiley Happy Could you accept the corresponding reply as solution to help others who has similar issue easily find the answer and close this thread?

 

Regards

View solution in original post

11 REPLIES 11
Vvelarde
Community Champion
Community Champion

@Anonymous

 

hi, you can use TOPN

 

SumTOPN =
CALCULATE ( SUM ( Table2[Value] ), TOPN ( 10, Table2, Table2[Value] ) 



Lima - Peru
Anonymous
Not applicable

I tried with TOPN also but this does not work 😕 any idea why?

I read that TOPN does not guarantee correct sorting

KHorseman
Community Champion
Community Champion

TOPN doesn't guarantee any particular sort order to the results, but the results are the correct top N results. So summing them up should work fine; 1 + 2 + 3 + 4 is the same as 1 + 3 + 4 + 2. What is wrong with the results you're getting? Can you give a sample that doesn't give the correct sum?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

@KHorseman  It works but the thing I want is, the TOPN sum to be grouped by Column1. How can I do that? This does not group by Column1 it only returns the sum of the first 10 rows.

KHorseman
Community Champion
Community Champion

Are you saying you want to see the top n rows with a sum for each row? If that's all, the latest desktop release makes it super easy; you just need a regular sum formula, then put a top n filter on the visual.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

@KHorseman no, I want the SUM of the TOP N rows as a measure.

For example if I have this table and I want the sum od TOP 3:

 

A 15     

B 20

C 30

D 10  ====> A 35

A 20                B 30
B 10                C 55
C 25                D 10

 

I would get 35+30+55=120

 

 

Do you know how can I do that?

KHorseman
Community Champion
Community Champion

@Anonymous the formula @Vvelarde gave should work for that.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Look

Screenshot_6.png

The SumTOPNa expression is: 

SumTOPNa = CALCULATE(sum(Table1[Column2]), TOPN (3, PieChart, SUM(Table1[Column2]), DESC))

Vvelarde
Community Champion
Community Champion

@Anonymous

 

You need  to group the categories to applied the aggregation.

 

One way is this:

 

 

Top2RL =
CALCULATE (
    SUM ( Table3[Value] ),
    TOPN (
        3,
        GROUPBY ( Table3, Table3[Category] ),
        CALCULATE ( SUM ( Table3[Value] ) )
    )
)



Lima - Peru
Anonymous
Not applicable

THANKS @Vvelarde!!! I've been trying to figure this out whole day 😄 

Hi @Anonymous,

 

Great to hear the problem got resolved.Smiley Happy Could you accept the corresponding reply as solution to help others who has similar issue easily find the answer and close this thread?

 

Regards

Helpful resources

Announcements
Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

charticulator_carousel_with_text (1).png

Charticulator Design Challenge

Put your data visualization and design skills to the test! This exciting challenge is happening now through May 31st!

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Power BI Release May 2022 768x460.png

Check it out!

Click here to read more about the May 2022 updates!