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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
tndanai
New Member

DAX Measure for HTS Rank: Issue with Rows Having HTS Number for Only One Country

I've created a DAX measure that calculates the rank for a product (HTS Number) across all countries when a country is selected via a slicer. The measure is used in a matrix visualization where each row represents an HTS Number. When no country is selected, I expect the rank column ("HTS Rank in World") to be blank, and it mostly works as expected.

However, when an HTS Number is associated with just one country in the dataset, the measure is returning a rank of 1 even when no country is selected.

Below is the DAX measure I'm currently using:

HTS Rank in World =
VAR CurrentHTSNumber = SELECTEDVALUE(Dictionary[HTS Number])
VAR CurrentCountry = SELECTEDVALUE(Master[Country])
VAR CYValueForCurrentHTSNumber = CALCULATE([CY Value], Master[Country] = CurrentCountry, Dictionary[HTS Number] = CurrentHTSNumber)

RETURN
IF(
ISBLANK(CYValueForCurrentHTSNumber),
BLANK(),
RANKX(
ALL(Master[Country]),
CALCULATE([CY Value], Dictionary[HTS Number] = CurrentHTSNumber),
CYValueForCurrentHTSNumber,
DESC,
Dense
)
)
dax problem 1.png


2 REPLIES 2
Mahesh0016
Super User
Super User

@tndanai I hope this helps you.
HTS Rank in World =
VAR CurrentHTSNumber =
SELECTEDVALUE ( Dictionary[HTS Number] )
VAR CurrentCountry =
SELECTEDVALUE ( Master[Country] )
VAR CYValueForCurrentHTSNumber =
CALCULATE (
[CY Value],
Master[Country] = CurrentCountry,
Dictionary[HTS Number] = CurrentHTSNumber
)
RETURN
IF (
ISBLANK ( CYValueForCurrentHTSNumber ),
BLANK (),
RANKX (
ALL ( Master[Country] ),
CALCULATE ( [CY Value], Dictionary[HTS Number] = CurrentHTSNumber ),
DESC,
DENSE
)
)

 Thank you for your help. I try the code, but the problem persists.  Seem the function Rankx not working well. 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.