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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
stmicbarr
Frequent Visitor

TOPN() function in SUMX is not returning the nth level value

I am having an issue with a measure including TopN filter where some of the top records are being exluded.  Example out of Top 10, ranks 9 and 10 are not included in the calculation.

 

Here is the formula:

Top 10 By Customer =

SUMX(

    TOPN(

        10,

        SUMMARIZE(

            ALLSELECTED('Sales’),

            ‘Sales’[Customer],

            "YTD",[Sales YTD]),

        [YTD],

 DESC

    ),

    [Sales YTD]

)

 

Here are the results:

 

RankCustomerSales YTDTop 10 Customer
1A54,66654,666
2B41,26541,265
3C22,65922,659
4D17,86417,864
5E14,68914,689
6F12,46412,464
7G9,8949,894
8H9,8939,893
9I9,8009,800
10J6,148 

 

The calculation is taking place on a values table for sales volume. I have a filter applied from a lookup table so that the sales values are filtered to a specific department.

 

How can I fix this so that all of the Top 10 are included in the calculation?

1 ACCEPTED SOLUTION

Sorry, relatively new to posting. 

 

In the course of recreating my data model to share here but with the records masked, I found the issue.   I realized that the virtual table I had built should have referenced the Lookup table instead of the Values table.

 

Thanks for you prompts to share a complete sample data set!  I'll know better in the future.

View solution in original post

4 REPLIES 4
lbendlin
Super User
Super User

Please provide sample data that fully covers your issue.  Provide more than 10 rows of sample data.
Please show the expected outcome based on the sample data you provided.

Here is a small sample of the values table I am using for sales data.

 

Sales (volume)CustomerYearsWeeksDepartment
1615A20241Domestic
1360A20244Export
255B20243Online
1020B20248Online
340C20241Domestic
1530C20245Online
255C202415Online
1445D202420Export
170E20248Domestic
2295E202425Domestic
1275F20242Online
336F20247Online
425F202415Export
1445G20245Domestic
1275G202419Domestic
1530H20243Domestic
896H202414Domestic
255H202416Export
362H202422Export
...    

 

The lookup tables on this used in various visuals to provide filtering are simple.  Other values tables that use the lookup tables are those related to Budget volume, etc.

 

Customer

A

B
C
D
...

 

Department
Domestic
Import
Online
...

 

The 'YTD Sales' measure is a calculation that sums the Sales (volume) column for every week prior to the current one.

 

I need the measure from my originl post - 'Top 10 Customer' - to return the total sum of volume for all of the Customers who would make up the Top 10 by Sales volume.

 

In the example above, I would expect it to return the total volume of the Top 10 Customers, adjusting the top 10 list accordingly when filtered by Department.

 

When different department filters are applied, sometimes the measure works as I had intended.  Other times, it will not include the sales volume for the top 10, leaving out the volumes associated with the 9th and 10th place Customers.  

 

Testing it by increasing the TOPN function to 11 and higher, the 9th and 10th level begins to show up in the summation.

You say "Top 10 Customers"  but your sample data has only eight of them. Please provide sample data that fully covers your issue.
Please show the expected outcome based on the sample data you provided.

Sorry, relatively new to posting. 

 

In the course of recreating my data model to share here but with the records masked, I found the issue.   I realized that the virtual table I had built should have referenced the Lookup table instead of the Values table.

 

Thanks for you prompts to share a complete sample data set!  I'll know better in the future.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.