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
hellothere
Regular Visitor

TOPN query

I created a table called SALES_MGR_NET_SALES to list the Sales Managers and their Sales with this DAX expression:

 

SALES_MGR_NET_SALES = SUMMARIZE(DIM_CUST_REP_HIER,DIM_CUST_REP_HIER[Sales Mgr],"Sales",sum(FACT_SLS[Net Sales]))

 

I want to use SALES_MGR_NET_SALES to create a Top 10 Sales Managers list.  I created a second table TOP_TEN_SALES, which is suppposed to have the Top 10 Sales Managers, using this DAX expression:

 

TOP_TEN_SALES = TOPN(10,SUMMARIZE(SALES_MGR_NET_SALES,SALES_MGR_NET_SALES[Sales Mgr]),MAX(SALES_MGR_NET_SALES[Sales]))

 

However this results in the entire list of Sales Managers.  How do I get it to limit it to the top ten?

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi there

The 3rd argument of TOPN is evaluated in row context of the table supplied in the 2nd argument.
Because of that, you need to wrap the 3rd argument in CALCULATE to turn the row context into a filter context, i.e. ensure the expression is evaluated in a filter context corresponding to each sales manager.

MAX or SUM would both work here and nice you already have distinct sales managers.

TOP_TEN_SALES =
TOPN (
10,
SUMMARIZE ( SALES_MGR_NET_SALES, SALES_MGR_NET_SALES[Sales Mgr] ),
CALCULATE ( MAX ( SALES_MGR_NET_SALES[Sales] ) )
)

Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

2 REPLIES 2
OwenAuger
Super User
Super User

Hi there

The 3rd argument of TOPN is evaluated in row context of the table supplied in the 2nd argument.
Because of that, you need to wrap the 3rd argument in CALCULATE to turn the row context into a filter context, i.e. ensure the expression is evaluated in a filter context corresponding to each sales manager.

MAX or SUM would both work here and nice you already have distinct sales managers.

TOP_TEN_SALES =
TOPN (
10,
SUMMARIZE ( SALES_MGR_NET_SALES, SALES_MGR_NET_SALES[Sales Mgr] ),
CALCULATE ( MAX ( SALES_MGR_NET_SALES[Sales] ) )
)

Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

That worked. 

 

Thanks!

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.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.

March Power BI Update Carousel

Power BI Community Update - March 2026

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