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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
HappyZuil
Frequent Visitor

RANKX affected by item id when using ALL()

Goal: I have a table with all of the products from multiple stores, and I'm ranking them using a mix of RANKX calculations for different meassures (Total Sales and Total Items Sold). When a particular store is selected, the rank behaves as expected. The problem occours when multiple stores are selected.

Context: This is the dimension for "Articulo"

 

HappyZuil_2-1738683607351.png


Example: here the rank is fine. There are no gaps, and no duplicate values. 

 

HappyZuil_0-1738683203478.png


If I select both stores then the rank doesn't work as intended.

HappyZuil_1-1738683289532.png

 

My suspicion is that it has to do with ALL(Articulo). Here is the formula I use for this calculation:

 

 

 

Rank articulo basado en cantidad y venta = 
    RANKX (
        ALL(Articulo),
        RANKX (
             ALL(Articulo)
            ,[total ventas sin iva],
            ,DESC
        )    
        + DIVIDE (
            RANKX ( 
                ALL(Articulo)
                ,[Cantidad total vendida],
                ,desc
            ),
            (COUNTROWS 
                (CALCULATETABLE(
                     ALL(Articulo)
                ) )
            + 1 )
        ),
        ,
        ASC
        ,Dense
    )

 

 



Why do I use All(Articulo) instead of All(Articulo[articulo])? Because If I filter by Articulo[proveedor] then the rank is affected by this filter. Test using ALL(Articulo[articulo]):

 

 

Rank articulo basado en cantidad y venta = 
    RANKX (
        ALL(Articulo[articulo]),
        RANKX (
             ALL(Articulo[articulo])
            ,[total ventas sin iva],
            ,DESC
        )    
        + DIVIDE (
            RANKX ( 
                ALL(Articulo[articulo])
                ,[Cantidad total vendida],
                ,desc
            ),
            (COUNTROWS 
                (CALCULATETABLE(
                     ALL(Articulo[articulo])
                ) )
            + 1 )
        ),
        ,
        ASC
        ,Dense
    )

 

 


Works fine when all stores selected, but the rank changes when filtered by Articulo[proveedor].

HappyZuil_3-1738683786657.png

HappyZuil_4-1738683814060.png

Any hints? Thanks a lot.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi,

Thanks for the solution parry2k  offered,and i want to offer some more information for user to refer to.

hello @HappyZuil , based on your description, you can create a rank calcukated column in your demional table so that it will not change, 

In Articulo, creaet a Sum column.

Sum =
CALCULATE ( [total ventas sin iva], RELATEDTABLE ( 'yourfacttable' ) )

Then create a rank column.

Rank=RANKX(Articulo,[Sum],,ASC)

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

3 REPLIES 3
parry2k
Super User
Super User

@HappyZuil use ALLSELECTED() instead of ALL()



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Using ALLSELECTED(Articulo[articulo]) yield the same result as using ALL(Articulo[articulo]), which is what I'm trying to avoid: it recalculates the rank when filtered by Articulo[proveedor]. In this picture, ALL() is closer to what I want to achieve.

 

HappyZuil_0-1738697773357.png

 

Anonymous
Not applicable

Hi,

Thanks for the solution parry2k  offered,and i want to offer some more information for user to refer to.

hello @HappyZuil , based on your description, you can create a rank calcukated column in your demional table so that it will not change, 

In Articulo, creaet a Sum column.

Sum =
CALCULATE ( [total ventas sin iva], RELATEDTABLE ( 'yourfacttable' ) )

Then create a rank column.

Rank=RANKX(Articulo,[Sum],,ASC)

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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