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
riguberto
Frequent Visitor

Get top n value considering duplicate values

Hello, 

 

I'm trying to set 3 different dax metrics to get the 1st,2nd,3rd values of a product price (for diferents urls).

product_idurl_idLastPriceproduct_priceInvalidPrice
1589461123584114,770
1589462541222114,770
158946455333130,540
1589465648124115,231
1589461325444127,90

 

Best Price= 14,77

Second best price=14,77

Third best price=27,90

Browsing the forum I have found this formula and it works when they are not duplicated values.

 

 

Second Best Price = 
SUMx (
    TOPN(1,
        TOPN ( 2, FILTER(priceregistrationraw,and(NOT(priceregistrationraw[InvalidPrice]=1),priceregistrationraw[LastPrice]=1)), [price] , ASC ),
        [price] , DESC
    ),
    CALCULATE ( min ( priceregistrationraw[price])))

 

 

 

But as long as Top N shows duplicates, it sums their values. Can you help me?

 

thanks in advance!

1 ACCEPTED SOLUTION
harshnathani
Community Champion
Community Champion

Hi @riguberto ,

 

Is this what you are looking for.

 

https://community.powerbi.com/t5/Desktop/Top-3-unique-products-sold-per-product-category-on-which-da...

 


Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

View solution in original post

6 REPLIES 6
harshnathani
Community Champion
Community Champion

Hi @riguberto ,

 

Create a Calculated Column

 

rank =

IF('Table'[LastPrice] = 1 && 'Table'[InvalidPrice] = 0,
Rankx(FILTER('Table','Table'[LastPrice] = 1 && 'Table'[InvalidPrice] = 0),'Table'[product_price],,DESC,Dense))
 
 
Then create these measures
Best Price =
MAXX(
SUMMARIZE('Table','Table'[product_price],'Table'[rank],"Best",CALCULATE(MAX('Table'[product_price]),'Table'[rank] =1)),[Best])
 
 
Second Price =
MAXX(
SUMMARIZE('Table','Table'[product_price],'Table'[rank],"Best",CALCULATE(MAX('Table'[product_price]),'Table'[rank] =2)),[Best])
 
 
Third Price =
MAXX(
SUMMARIZE('Table','Table'[product_price],'Table'[rank],"Best",CALCULATE(MAX('Table'[product_price]),'Table'[rank] =3)),[Best])
 
 
1.jpg
 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

amitchandak
Super User
Super User

@riguberto , Try like

 

rank =	rankx(FILTER(priceregistrationraw,and(NOT(priceregistrationraw[InvalidPrice]=1),priceregistrationraw[LastPrice]=1)),[price],,ASC,Dense)

Second Best Price = 
sumx(filter(priceregistrationraw,[Rank]=2),CALCULATE ( min ( priceregistrationraw[price])))

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thanks for your response. 

 

rank... creating this metric pop up the error: can't determine the value of price. Maybe the column doesn't exist or it is no rows (translating myseflt from spanish... :S)

 

 

ok, I didn't understood that rank was a column in the priceregistrationraw table (I was trying as a metric (I'm totally newby)).

 

My problem now is that the table has more products_id and they are getting ranked all together. I tried to put a product_id filter, but now the filter for lastprice and isvalid are not working (the product_id looks fine)...

 

What I tried

rank = rankx(FILTER(priceregistrationraw,and(NOT(priceregistrationraw[InvalidPrice]=1),AND(priceregistrationraw[LastPrice]=1,priceregistrationraw[product_id]=EARLIER(priceregistrationraw[product_id])))),[total_price_numeric],,ASC,Dense)
harshnathani
Community Champion
Community Champion

Hi @riguberto ,

 

Is this what you are looking for.

 

https://community.powerbi.com/t5/Desktop/Top-3-unique-products-sold-per-product-category-on-which-da...

 


Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

Thanks! this solution is working.

 

My only concerne is about performarnce. The priceregistrationraw table is a fact table with more than 10Million rows... is efficient to create a new table with the same info? 

 

thanks again

 

 

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