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
Anonymous
Not applicable

Select topn value without duplicate

Hi floks,
Here I facing an difficulties, that want to select TOP 20 rows from the table without duplicate of the same values.
I have tried these DAX to achive but it returns dupliacte rows.
DAX Query: TOPN(20,factQuotes,factQuotes[TotalValue],DESC)
it returns like shown below

Sivanesan02_0-1599569515672.png

Can any one please help me to crack this.


Thanks in advance,
Sivanesan C



1 ACCEPTED SOLUTION
v-zhenbw-msft
Community Support
Community Support

Hi @Anonymous ,

 

We create a sample, that Total has two rows same value.

 

Se1.jpg

 

Then we can create a calculate table using the following formula.

 

Table 2 = 
TOPN (
    20,
    SUMMARIZE (
        'factQuotes',
        'factQuotes'[Total],
        "name", CALCULATE ( MAX ( 'factQuotes'[name] ) )
    ),
    'factQuotes'[Total], ASC
)

 

se2.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

 

Best regards,

 

Community Support Team _ zhenbw

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

 

BTW, pbix as attached.

View solution in original post

9 REPLIES 9
SonalPowerBI
New Member

This solution is not working for me. When I create new table same like above, I not getting fields which I require. Is there any other solution. how to resolve tie when showing TOP 5 as I am getting more than TOP N values

v-zhenbw-msft
Community Support
Community Support

Hi @Anonymous ,

 

We create a sample, that Total has two rows same value.

 

Se1.jpg

 

Then we can create a calculate table using the following formula.

 

Table 2 = 
TOPN (
    20,
    SUMMARIZE (
        'factQuotes',
        'factQuotes'[Total],
        "name", CALCULATE ( MAX ( 'factQuotes'[name] ) )
    ),
    'factQuotes'[Total], ASC
)

 

se2.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

 

Best regards,

 

Community Support Team _ zhenbw

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

 

BTW, pbix as attached.

Anonymous
Not applicable

Hi @v-zhenbw-msft ,
Thank you for your help.
Actually by your solution, I have change some data's in datawarehouse now its perfectly works as expected.


Thanks,
Sivanesan C

Anonymous
Not applicable

Hi @v-zhenbw-msft ,
Really very thankfull to you.
I got the partial solutions from that, because in my data I have replication on Quote ID aslo.
If you have any idea, please help me to get out it.


Thank you,
Sivanesan C

Hi @Anonymous ,

 

Sorry for that we don’t know which column is Quote ID, maybe you can refer the following method.

 

1. In Power Query Editor, remove the duplicates in the columns that you want to remove the duplicates.

 

se1.jpg

 

2. Then we need to sort the Total column.

 

se2.jpg

 

se3.jpg

 

3. Then we add an index column.

 

se4.jpg

 

4. At last we can filter the data that Index is less than or equal to 20. Or we can create a new table using Filter function.

 

se5.jpg

 

Table = SUMMARIZE(FILTER(factQuotes,factQuotes[Index]<=20),factQuotes[name],factQuotes[Total])

 

se6.jpg

 

If it doesn’t meet your requirement, could you please provide a mockup sample based on fake data or describe the fields of each tables and the relations between tables simply?

 

Please upload your files to OneDrive For Business and share the link here. Please don't contain any Confidential Information or Real data in your reply.

 

Best regards,

 

Community Support Team _ zhenbw

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

 

BTW, pbix as attached.

amitchandak
Super User
Super User
Greg_Deckler
Community Champion
Community Champion

@Anonymous - Perhaps try adding a small RAND() number to break ties.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hi @Greg_Deckler ,
I have try to add RAND(), But again I get the value in top @20 

Sivanesan02_0-1599571617293.png

 

@Anonymous - Throw in a DISTINCT somewhere?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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
Top Kudoed Authors