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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Ethanhunt123
Helper IV
Helper IV

Top N for only specific category (Avoid blanks)

I have a table that has 2 columns, Test_Name , Test_Value

Test_NameTest_Value
ABC10
SDF12
ERT14
ASD 

 

I have to find the top 1 Test_name based on the Test_value 

 

My DAX looks like this

 

Test =

CALCULATE (
( Test_Name),
TOPN ( 1, ALL(Test_Name) , Test_value DSC),
VALUES ( test_Name )
)
 
The output I am getting is ASD( which is not correct, it should not consider blank values) The output should be ERT
1 ACCEPTED SOLUTION
v-kelly-msft
Community Support
Community Support

Hi  @Ethanhunt123 ,

 

Create a measure as below:

Measure = 
CALCULATE(MAX('Table'[Test_Name]),TOPN(1,FILTER(ALL('Table'),'Table'[Test_Value]<>BLANK()),CALCULATE(MAX('Table'[Test_Value])),DESC))

And you will see:

Screenshot 2020-09-14 133540.png

For the related .pbix file,pls see attached.

 
Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

 

View solution in original post

5 REPLIES 5
negi007
Community Champion
Community Champion

@Ethanhunt123  You can create below simple measure to obtain the value against TOP value.

 

Top_Val = LOOKUPVALUE('Top N'[Test_Name],'Top N'[Test_Value],Max('Top N'[Test_Value]))
 
 
negi007_0-1600063341778.png

 

 




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



Proud to be a Super User!


Follow me on linkedin

v-kelly-msft
Community Support
Community Support

Hi  @Ethanhunt123 ,

 

Create a measure as below:

Measure = 
CALCULATE(MAX('Table'[Test_Name]),TOPN(1,FILTER(ALL('Table'),'Table'[Test_Value]<>BLANK()),CALCULATE(MAX('Table'[Test_Value])),DESC))

And you will see:

Screenshot 2020-09-14 133540.png

For the related .pbix file,pls see attached.

 
Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

 

PaulDBrown
Community Champion
Community Champion

@Ethanhunt123 

 

Use RANKX instead of TOPN

(The name of the table in my exampe is 'TopN')

 

 

Rank Value = RANKX(ALL('TopN'), [Sum of Value],,DESC)

 

 

result.JPG

 

and if you want a measure for the top name only:

 

 

Top Name for Card Visual = CALCULATE(MAX('TopN'[Test_Name]), FILTER('TopN', [Rank Value] = 1))

 

 

card vis.JPG

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






amitchandak
Super User
Super User

@Ethanhunt123 , Try like measures like

 

measure = calculate(sum(Test_Value), filter(Table,not(isblank(Table[Test_Value]))))

 

CALCULATE (
[measure],
TOPN ( 1, ALL(Test_Name) , [measure] DSC),
VALUES ( test_Name )
)

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

The output would be Test_name, This is still giving me TEST_Name with the blank value

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.