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
Talal141218
Helper III
Helper III

TOPN function with filter

Hello Community, 

I am trying to create a formula in TOPN to select Top 10 customers' sales

CALCULATE(Fact_SalesInvoiceLine[CM_SalesInvoiceLine_Amount_ExclAll_LCY],TOPN(10,VALUES(Dim_Customer[CustomerName]),Fact_SalesInvoiceLine[CM_SalesInvoiceLine_Amount_ExclAll_LCY]))

, but when i create it, show me all customers' sales but the total of sales is for Top 10 customers' name. Please let me know if you need more Info.

as below: 

Talal141218_1-1689252506889.png

Thanks in advance for your suggestions. 

1 ACCEPTED SOLUTION

How about

 

Top Sales =
VAR Top10 =
    TOPN (
        10,
        ALLSELECTED ( Dim_Customer[CustomerName] ),
        [CM_SalesInvoiceLine_Amount_ExclAll_LCY]
    )
RETURN
    CALCULATE ( [CM_SalesInvoiceLine_Amount_ExclAll_LCY], KEEPFILTERS( Top10 ) )

 

View solution in original post

5 REPLIES 5
johnt75
Super User
Super User

Try

Top Sales =
CALCULATE (
    [CM_SalesInvoiceLine_Amount_ExclAll_LCY],
    TOPN (
        10,
        ALLSELECTED ( Dim_Customer[CustomerName] ),
        [CM_SalesInvoiceLine_Amount_ExclAll_LCY]
    )
)

I got this, when i applicate your formula, Thanks for your interesting 

Talal141218_0-1689255532362.png

 

How about

 

Top Sales =
VAR Top10 =
    TOPN (
        10,
        ALLSELECTED ( Dim_Customer[CustomerName] ),
        [CM_SalesInvoiceLine_Amount_ExclAll_LCY]
    )
RETURN
    CALCULATE ( [CM_SalesInvoiceLine_Amount_ExclAll_LCY], KEEPFILTERS( Top10 ) )

 

Sorry, the same result 

I've edited my post to add KEEPFILTERS, I think that should do it.

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.