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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.