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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Morrison
Helper I
Helper I

Rankx with condition on a measure

Hello, I would like to create a rank excluding all stores that have sales below a certain amount. 

I try this but dont run

 

RankX_filteronsales =
VAR PRODCUTRANKX = IF( [Tot Venduto Gara] > 264,
                                    RANKX( filter (ALL('dwh DimStore'), 'dwh DimStore'[StoreStatus] = "A" && [Tot Venduto Gara] > 264  ),
                                    CALCULATE(SUMX('Venduto Totale','Venduto Totale'[Gara_Tot_venduto]),
            DESC,
            DENSE
        ),
        BLANK ()
    )
RETURN
PRODCUTRANKX
 

This is the result I would like to get

 

StoreSales Rank
A200 
B3003
C3012
D3021
1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

I hope the below can provide some ideas on how to create a solution for your datamodel.

 

Jihwan_Kim_1-1669035921344.png

 

 

Jihwan_Kim_0-1669035887561.png

 

Sales measure: = 
SUM( Sales[Sales] )

 

Rank measure expected: =
IF (
    [Sales measure:] > 264
        && HASONEVALUE ( Store[Store] ),
    RANKX (
        FILTER ( ALL ( Store[Store] ), [Sales measure:] > 264 ),
        [Sales measure:],
        ,
        DESC
    )
)

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

I hope the below can provide some ideas on how to create a solution for your datamodel.

 

Jihwan_Kim_1-1669035921344.png

 

 

Jihwan_Kim_0-1669035887561.png

 

Sales measure: = 
SUM( Sales[Sales] )

 

Rank measure expected: =
IF (
    [Sales measure:] > 264
        && HASONEVALUE ( Store[Store] ),
    RANKX (
        FILTER ( ALL ( Store[Store] ), [Sales measure:] > 264 ),
        [Sales measure:],
        ,
        DESC
    )
)

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Hi @Jihwan_Kim ,

thx for the support.

I tried adding a new dimension and the function no longer returns the desired result. I'll show you what I see after adding the new AreaManager dimension. 

 

AreaManagerStoreRankTot Sales
AAA11
BBB12
CCC13
DDD14
EEE15
FFF16
FGG27

Hi,

Thank you for your feedback.

The measure depends on how the datamodel is structured.

Please share the link of your sample pbix file with how your desired outcome looks like, and then I can try to look into it to come up with a more accurate solution.

Thanks.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Hi @Jihwan_Kim ,

i solved this way. Thx

 

Rank =
VAR tmpVal = [Tot Q.tà gara]
RETURN
        IF(tmpVal < 60, BLANK(),
            RANKX(
                FILTER(
                        ALL('dwh DimStore'),
                        'dwh DimStore'[StoreStatus] = "A"
                        ),
               CALCULATE(SUMX('Venduto Totale','Venduto Totale'[Gara_Tot_quantita])
                ),,DESC,Dense
            )
        )

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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