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
harmon-tuazon
New Member

TOPN Functions returns the same value as my COUNT aggregate function

Hey everyone. Sorry super new to posting. I have a measure that supposed to return the top 10 values of a table I'm working with (using Calculate and TopN). I have another measure that just aggregates values (using Count). However, as seen on the matrix table screenshot I attached here, the TOPN measure returns the same values as my other measure. Any idea why the TOPN isn't filtering the calculation? TIA

Screenshot 2024-08-21 152208.pngScreenshot 2024-08-21 152234.pngScreenshot 2024-08-21 152246.png

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file whether it suits your requirement.

 

Jihwan_Kim_0-1724298688759.png

 

Sales: = 
SUM(data[sales])

 

% top 3 sales: =
VAR _allsales =
    CALCULATE ( [Sales:], ALL ( data[category] ) )
VAR _topsales =
    CALCULATE ( [Sales:], TOPN ( 3, ALL ( data[category] ), [Sales:], DESC ) )
RETURN
    DIVIDE ( _topsales, _allsales )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Thanks for the reply from Jihwan_Kim.

 

Hi @harmon-tuazon ,

 

Here I have another idea in mind, and I would like to share it for reference.Sample data is as follows:

vlinhuizhmsft_0-1724320089613.png

 

1.Create two measure:

 

#Meal Kits = COUNT(financials[Index])


#Top 10 Meal Kits Ordered =
VAR _p =
    SELECTEDVALUE ( financials[Product] )
RETURN
    MAXX (
        FILTER (
            TOPN (
                3,
                SUMMARIZE (
                    ALLSELECTED ( financials ),
                    'financials'[Product],
                    "Top",
                        CALCULATE (
                            COUNT ( 'financials'[Index] ),
                            ALLEXCEPT ( financials, financials[Product] )
                        )
                ),
                [Top], DESC
            ),
            'financials'[Product] = _p
        ),
        [Top]
    )

 

 

2.The top three product totals were successfully obtained using the measure just created.

 vlinhuizhmsft_1-1724320640227.png

vlinhuizhmsft_3-1724320979079.png

 

Best Regards,
Zhu
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file whether it suits your requirement.

 

Jihwan_Kim_0-1724298688759.png

 

Sales: = 
SUM(data[sales])

 

% top 3 sales: =
VAR _allsales =
    CALCULATE ( [Sales:], ALL ( data[category] ) )
VAR _topsales =
    CALCULATE ( [Sales:], TOPN ( 3, ALL ( data[category] ), [Sales:], DESC ) )
RETURN
    DIVIDE ( _topsales, _allsales )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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