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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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