Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
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
)
)
@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.
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
| User | Count |
|---|---|
| 12 | |
| 9 | |
| 9 | |
| 5 | |
| 4 |
| User | Count |
|---|---|
| 27 | |
| 22 | |
| 20 | |
| 17 | |
| 12 |