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
Anonymous
Not applicable

Filter transactions while RANKX

Hi,

 

While ranking using RANKX, is it posible to filter the transaction based on some criteria ?

 

I created a measure like this :

Rank = 
VAR tmpVal = SUM('Transactions'[Item qty])
RETURN
        IF(tmpVal = 0, BLANK(),
            RANKX(
                ALL('Products'[Item id]),
                CALCULATE(
                            SUM('Transactions'[Item qty]),
                            'Products'[Product type] = 1                            
                )
            )
        )

The explanation to that, I put a filter inside the CALCULATE, for the transactions only for product with type = 1, which just some category inside my Product master.

 

But the result I get now is :

medwong_0-1620670334351.png

If I remove the filter of product type then it is correct. 

Should I filter my Product as well ? it is seems odd, because if the transactions already filter, why they need to rank products which not in the transactions anyway.

 

Thanks,

 

2 REPLIES 2
daxer-almighty
Solution Sage
Solution Sage

You're not ranking transactions but products. And products have the types you mention, not transactions. It's not entirely clear what you're after since the description is misleading. Would you care to show what the correct output should look like, please? And please try to clarify your description.

Anonymous
Not applicable

Hi @daxer-almighty ,

 

I'm sorry, may I ask which one is not clear ? Maybe what a bit confusing is between "item id" and "product type code" ? item id is same like "product id", while "product type code" is another field inside my Product master, which use for a category, and right now I only want to rank products with type code =1 within my transactions. 

 

For the correct / expected output, I think can refer to the image, I've sort the column "Item qty", so the rank should follow that order.

 

However, I tried to change the measure, to filter the Product instead like this :

Rank = 
VAR tmpVal = SUM('Transactions'[Item qty])
RETURN
        IF(tmpVal = 0, BLANK(),
            RANKX(
                FILTER(
                        ALL('Products'),
                        'Products'[Product type code] = 1
                        ),
                CALCULATE(
                            SUM('Transactions'[Item qty])               
                ),,DESC,Dense
            )
        )

It looks "correct" a bit, only there is one double rank like below:

medwong_0-1620673333193.png

Thanks

 

 

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!

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.