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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

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

@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

13 REPLIES 13
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

Anonymous
Not applicable

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?

Anonymous
Not applicable

@Anonymous  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.

Anonymous
Not applicable

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.

Anonymous
Not applicable

@Anonymous 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?

Anonymous
Not applicable

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

Anonymous
Not applicable

Look

Screenshot_6.png

The SumTOPNa expression is: 

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

@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

It works but when we try to filter values further. it returns blank table. How we can fix that?

Anonymous
Not applicable

You're amazing! Thank you for this answer.

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.