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 September 15. Request your voucher.

Reply
Anonymous
Not applicable

Why topN function not working in Selectedvalues

HI 

I am trying to get top 3 customer based on Selected values, but does not working 

Top 3 Customers =

IF(
SELECTEDVALUE('2425'[SBUName])=MAX('2425'[SBUName]),
CALCULATE(
SUM('2425'[ValuesinLakhs]),
TOPN(3,ADDCOLUMNS(VALUES('2425'[Customer Name]),"@Test",MROUND(SUM('2425'[ValuesinLakhs]),5)
),
[@Test],DESC,'2425'[Customer Name], ASC)

)
)

 

Sudhakar1000_0-1729840491497.png

 

5 REPLIES 5
bhanu_gautam
Super User
Super User

@Anonymous , Try using 

 

Top 3 Customers =
CALCULATE(
SUM('2425'[ValuesinLakhs]),
TOPN(
3,
SUMMARIZE(
'2425',
'2425'[Customer Name],
"@Test", SUM('2425'[ValuesinLakhs])
),
[@Test], DESC,
'2425'[Customer Name], ASC
),
'2425'[SBUName] = SELECTEDVALUE('2425'[SBUName])
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Anonymous
Not applicable

Hi Bhanu,

Not getting change 

Sudhakar1000_0-1729844006631.png

 

Anonymous
Not applicable

Thanks for the reply from bhanu_gautam , please allow me to provide another insight:

Hi, @Anonymous 

Your idea is excellent. Below are my sample data and alternative solutions, which I hope you find helpful:

vlinyulumsft_0-1730095381778.png

1.Firstly, using measures:

Top 3 Customers =
VAR name1 =
    SELECTCOLUMNS (
        TOPN ( 3, ALLSELECTED ( '2425' ), '2425'[ValuesinLakhs], DESC ),
        "name", '2425'[Customer Name]
    )
RETURN
    IF (
        MAX ( '2425'[Customer Name] ) IN name1,
        SUMX (
            FILTER ( '2425', '2425'[Customer Name] IN name1 ),
            MROUND ( '2425'[ValuesinLakhs], 5 )
        ),
        BLANK ()
    )

Here are the final results:

vlinyulumsft_1-1730095425086.png

Of course, I recommend modifying the following filters to enhance the data further:

vlinyulumsft_2-1730095425086.png

vlinyulumsft_3-1730095432065.png

2.Secondly, directly using Top N in the filters:

vlinyulumsft_4-1730095456856.png

 

Next, rounding the measures:

Measure = MROUND(SUM('2425'[ValuesinLakhs]),5)

Here are the final results, which I hope will meet your needs:

vlinyulumsft_5-1730095480985.png

Both of these options have their advantages and disadvantages, so you can choose based on your requirements.

 

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

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

 

Anonymous
Not applicable

Hi Leroy Lu,

Thank you for giving best. here can we go with SBU wise topn,

If A  top 3.

B top 5.

C Top 10 LIke... 

Anonymous
Not applicable

Hi, @Anonymous 

Thank you for your swift response.

 

You can modify the measure as follows:

Top 3 Customers = 
VAR select1=MAX('2425'[SBUName])
VAR number1=SWITCH(TRUE(),select1="A",3,select1="B",5,select1="C",10,3)
VAR name1 =
    SELECTCOLUMNS (
        TOPN (number1, ALLSELECTED ( '2425' ), '2425'[ValuesinLakhs], DESC ),
        "name", '2425'[Customer Name]
    )
RETURN
    IF (
        MAX ( '2425'[Customer Name] ) IN name1,
        SUMX (
            FILTER ( '2425', '2425'[Customer Name] IN name1 ),
            MROUND ( '2425'[ValuesinLakhs], 5 )
        ),
        BLANK ()
    )

Incorporate the switch() function for evaluation.

 

Best Regards,

Leroy Lu

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

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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