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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Totoro
New Member

Top N filter plus one specific item

Hi

The data and desired outcome (top 3 in rank plus colour=pink if it is not in tope 3) are as below:

data.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

outcome.png

 

 

 

 

 

 

 

 

The measure Rank = RANKX(ALL(TableData[Colour]),CALCULATE(SUM(TableData[Stock]))) seems ok but the other measure

Top3+Pink = IF([Rank]<4 ||'TableData'[Colour] = "Pink",1,0) doesn't work.  Any advice please.  Thanks.

 

 

 

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

6 REPLIES 6
tamerj1
Super User
Super User

Hi @Totoro 
Please refer to attached sample file with the solution

2.png

Top 3 Stock = 
VAR T1 = 
    CALCULATETABLE (
        VALUES ( Data[Colour] ), 
        ALLEXCEPT ( Data, Data[Category] ) 
    )
VAR T2 = TOPN ( 3, T1, [Total Stock] )
VAR T3 = UNION ( T2, { "Pink" } )
VAR T4 = FILTER ( Data, Data[Colour] IN T3 )
RETURN 
    SUMX ( T4, [Total Stock] )

 

 

Many thanks tamerj1 for the code and pbix file! Should have posted the question earlier I have been struggling with it for weeks.

 

wdx223_Daniel
Super User
Super User

wdx223_Daniel_0-1677573570233.png

 

It works! Brilliant! Thanks wdx223_Daniel.

 

Regards

Totoro

andhiii079845
Super User
Super User

I think this can help you:

https://community.powerbi.com/t5/Desktop/Rankx-with-filter/m-p/63457





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks andhiii079845 for the reference.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors