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

How to assign Rank for zero but exclude null or blank values

Hi,
I have the following tables
Dim : 

LocationCodeNameLocationcode
AA001
BB001
CC001
DD001
EE001
FF001

 SalesFact : 

LocationcodeQty
A0018
B00120
E00160
F00140
C00122

Target:

LocationcodeTarget
A00110
B00120
E00130
F00140
C00120

Target % = Divide(Sales- Target , Target) *100
So i need to calculate rank as follows:

LocationCodeNameQtyTargetTarget %Rank
A810-204
B202003
C2220102
D    
E60301001
F404003


Rank should be given based on highest to lowest target% including 0 (which means the location has met its target completely - Location B001 and F001 in this case) however excluding non-existing location (means no target was given to these location in this month - Location D001 in this case). 

I tried the following DAX formula but it doesnt work for null values (where there was no target given):

 

Location Ranking =
 RANKX(All('dim'[LocationCodeName])
    ,
    CALCULATE( [# Target %]),,desc,dense
    )
but this is giving rank to blank and 0 as same rank. 

Thanks in Advance!
1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

4 REPLIES 4
lbendlin
Super User
Super User

lbendlin_0-1694740921177.png

 

Thanks @lbendlin for your response, 
It's working perfectly. Really appreciate it. 

 

Also, I found another way to resolve this :

if(NOT(ISBLANK([Target %])), rankx(FILTER(ALL('dim'[LocationCodeName]),NOT(ISBLANK([Target]))),CALCULATE([Target %]),,,Dense),BLANK())

If you are interested you can run both versions of this through DAX Studio and compare the query plans and server timings.

 

CALCULATE([Target %])  seems redundant.

Yeah, you are right @lbendlin . Much appreciated. Thanks again 🙂

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!

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.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.