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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
MichalDe
Frequent Visitor

Topn with additonal filter

Hi

I'm new in Power and I've got a problem with TOPN function with additonal FILTER on Dates. What am I doing wrong in this case?

 

I want to get the column with TOP 10 customers for all dates (all period) equals $ 135k in each rows next to this column with "Total Sales"

 

Top 10 customers by " total sales" for all dates (all period - no filters on dates) is as below = $ 135 k

1.jpg

 

I was tring to get this by using measure like below but no vain.

 

Top 10 All Time = CALCULATE([Total Sales],
TOPN(10, ALL('Customer'), [Total Sales], DESC),
ALL('Date'[Date])
)
 
but
 
obraz.png
 

Thanks in advance for your help

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @MichalDe ,

 

Got it. I have reached your expected in two ways please check.

 

  • Method 1:

1. Create a table:

 

Sum top10 table = SUMMARIZE('Date',"Top10", SUMX(TOPN(10, ALL(Customer[Full Name]),[Total Sales],DESC),[Total Sales]) )

 

2. Create a measure:

 

Top 10 All Time = IF([Total Sales]=BLANK(),BLANK(),MAX('Sum top10 table'[Top10]))

 

 

 

  • Method 2:

1.Create a new Year table:

 

New Table = SELECTCOLUMNS(FILTER('Date',[Total Sales]<>BLANK()),"Year",[Year])

 

2.Create new total sales measure:

 

new total sales = CALCULATE([Total Sales],FILTER('Date',[Year]=MAX('New Table'[Year])))

 

3. Top10:

 

new top10 = SUMX(TOPN(10,ALL(Customer[Full Name]),[Total Sales],DESC),[Total Sales])

 

The final output is shown below:

top10 method1.PNG

top10 method2.PNG

 

 

In addition, when I open your pbix file, an alert dialog shown :  

earlier version.PNG

It seems that your PBI is in an earlier version, so please upgrade it to the latest version and have a try.

Download Microsoft Power BI Desktop from Official Microsoft Download Center

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

10 REPLIES 10
Syndicate_Admin
Administrator
Administrator

Hello good day

I am analyzing the sales by Store and the Top product of each.

aztirma_0-1692310905450.png

When you filter by month, it gives the correct result (verified with the table below filtering each store)

aztirma_1-1692311283681.png

But when I filter for April, June and December I get an error

aztirma_2-1692311340811.png

I have these filters applied

aztirma_4-1692311399562.png

the TopN dax is:

TOP Product =
CALCULATE(
TOPN(
1,
VALUES(Items[Item Name]),
[Total Sales wc]),
ALLSELECTED(Stores[Store Name]), VALUES(Stores[State]), ALLSELECTED('Date'))

The sales dax is:
Total Sales wc =
SUMX(
Sales, Sales[Bottles Sold] *
RELATED(Items[Bottle Sale]))


The truth is I do not know what happens, every month has sales

aztirma_6-1692311693492.png

If please tell me what I am doing wrong

Thank you very much


Anonymous
Not applicable

Hi @MichalDe ,

 

Got it. I have reached your expected in two ways please check.

 

  • Method 1:

1. Create a table:

 

Sum top10 table = SUMMARIZE('Date',"Top10", SUMX(TOPN(10, ALL(Customer[Full Name]),[Total Sales],DESC),[Total Sales]) )

 

2. Create a measure:

 

Top 10 All Time = IF([Total Sales]=BLANK(),BLANK(),MAX('Sum top10 table'[Top10]))

 

 

 

  • Method 2:

1.Create a new Year table:

 

New Table = SELECTCOLUMNS(FILTER('Date',[Total Sales]<>BLANK()),"Year",[Year])

 

2.Create new total sales measure:

 

new total sales = CALCULATE([Total Sales],FILTER('Date',[Year]=MAX('New Table'[Year])))

 

3. Top10:

 

new top10 = SUMX(TOPN(10,ALL(Customer[Full Name]),[Total Sales],DESC),[Total Sales])

 

The final output is shown below:

top10 method1.PNG

top10 method2.PNG

 

 

In addition, when I open your pbix file, an alert dialog shown :  

earlier version.PNG

It seems that your PBI is in an earlier version, so please upgrade it to the latest version and have a try.

Download Microsoft Power BI Desktop from Official Microsoft Download Center

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks a lot.

Method 1 works perfectly.
Stil wondering why in my measure, All(date[date]) function as a "filter2" embedded in CALCULATE statement doesn't change filter context for year in the raport table.

Anonymous
Not applicable

Hi @MichalDe ,

 

I used the data sample you provided, was it not your real data ?

 

Both measures below work fine on my side. Please try :

Top 10 All Time = IF( RANKX(ALL('Date'),[Total Sales],,DESC,Dense)<=10,[Total Sales])
Top 10 All Time = CALCULATE([Total Sales],TOPN(10,ALL(Customer[Full Name]),[Total Sales],DESC),ALL('Date'[Year]))

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @Anonymous 
Thank for your reply. Could you send me your screenshot with the table to see how it looks?

In my file it still doesnt work. To be more precise I send the table preview that I would like to achieve. Does it look the same on your side?

 

MichalDe_1-1626421173984.png

 

 

 

 

Anonymous
Not applicable

Hi @MichalDe ,

 

Please try this:

Top 10 All Time = IF( RANKX(ALL('Internet Sales'),[Total Sales],,DESC,Dense)<=10,[Total Sales])

Top10.PNG

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

MichalDe
Frequent Visitor

Additionaly this measure

 

top 10 customers measure = CALCULATE([Total Sales],
TOPN(10, ALL('Customer'),
[Total Sales],
DESC))
 
yields 132 k and i do not know why this isint't corespoding with 135 k
Anonymous
Not applicable

Hi @MichalDe ,

 

I have built a data sample to easily understand:

top3.PNG

 

Actually I need more details such your tables ,your expected output... Can you please share more information or your pbix file after removing sensitive data to help us clarify your scenario?

 

In case ,below is how to rank by type,maybe could help you a little.

= RANKX (
    FILTER ( ALL ( 'Table' ), 'Table'[Type] = MAX ( 'Table'[Type]) ),
    CALCULATE ( MAX ( ( 'Table'[Value]) ) ),
    ,
    DESC
)

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

In your file it works, but in my file doesn't,. I do not know what is wrong. Maybe in my example the related table is used but the other hand shoud work anyway.

 

problem1.png

Hi


Thanks a lot for your reply.
The file I'm working on  is the workshop file so no sensitive data.

Please find attached file and look at "Problem" worksheet".

 

https://1drv.ms/u/s!Ak4rIGHJyQtTiHPu4ck0LGNeb2ML?e=row8sU

Thanks in advance for your reply.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors