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! Learn more

Reply
Anonymous
Not applicable

Correcting the blank value returned in TOPN for negative numbers

Hi, everyone. I'm trying to create a card which shows the name of the manager whose store ranked with most financial losses per month. I've implemented this with a data slicer and a map. The data slicer is segmented by State and Store Name and I wanna see the name of the manager of each store if it is selected in the data slicer too. However, there's a limitation in the Dax Formula I'm using it. That's because the value of financial losses can be negative or positive and whenever I select a store with negative value on the data slicer, my card returns blank value.

 

I'm using the following measure to show the Top1 manager of the month: 

Coordenador = CALCULATE(FIRSTNONBLANK('ABRIL 22'[COOR ATU],1),TOPN(1,ALLSELECTED('ABRIL 22'[COOR ATU]),[Perda Total],DESC))
 
Could somebody give me a hint?
 
1 ACCEPTED SOLUTION

Hi, @Anonymous 

Top N does not work with negative numbers. 

Please try to replace with function 'SAMPLE' .

Coordenador2 = CALCULATE(FIRSTNONBLANK('ABRIL 22'[COOR ATU],1),SAMPLE(1,'ABRIL 22',[Perda Total],DESC))

veasonfmsft_0-1652322868726.png

You can also create a sort column 'Rank' using ‘RANKX’, then filter data with ‘Rank’=1.

Please refer this related tread.

topn-dax-for-negative-values 

 

Best Regards,
Community Support Team _ Eason

View solution in original post

3 REPLIES 3
Whitewater100
Solution Sage
Solution Sage

Hi:

Do you have a small example file to help understand?   You can use ABS[Measure Name]) to give absolute values so it won't matter if positive or negative(if that's what you want).

Generally, this measure should help get top 1 no matter the tme frame you slice on:

If [Perda Total] = the financial loses and you have a separate dim

table for all of your unique financial managers names, e.g. Manager[Mgr Name] as one column in this table.

Top1 mgr = CALCULATE([Perda Total], 
                   TOPN(1, Managers[Mgr Name], DESC)

 

You should also have a separate Date Table where you can slice on month, year ,etc and the Top1 will show up based on your slections.

 

I hope this helps!

P.S. An example model is placed below so you can see the relationships which brings all the nalytical power.

Whitewater100_0-1652102980790.png

 

Anonymous
Not applicable

harrisoares_1-1652103812679.png

Currently, the dashboard is like this. In fact, there are 3 types of job titles related for each store. All three are blank whenever I select a Store with negative value for Total Loss. I don't think ABS() function would solve my problem because a negative value could rank higher than a positive value using this function. I just would like a way to use TOPN or another function considering negative and positive numbers on the ranking.

Hi, @Anonymous 

Top N does not work with negative numbers. 

Please try to replace with function 'SAMPLE' .

Coordenador2 = CALCULATE(FIRSTNONBLANK('ABRIL 22'[COOR ATU],1),SAMPLE(1,'ABRIL 22',[Perda Total],DESC))

veasonfmsft_0-1652322868726.png

You can also create a sort column 'Rank' using ‘RANKX’, then filter data with ‘Rank’=1.

Please refer this related tread.

topn-dax-for-negative-values 

 

Best Regards,
Community Support Team _ Eason

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.