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
aquanr18
Frequent Visitor

Creating a Rank for each Item By Custumer

Hi! tnx a lot for reading my post, 

My goal is to obtain the row TOP in powerr bi using rankx, 

 

2018-10-31 00_04_27-Libro1 - Excel.png

 

 

 

 

 

 

 

 

 

 

 

This is a rank for each item by customer in the same table. 

My data model looks like this. 

 

2018-10-31 00_06_38-we - Power BI Desktop.png

 

any Help will be much appreciated, 

Thanks!

1 ACCEPTED SOLUTION

@aquanr18 Please try this as a "New Column"

 

Top = RANKX(FILTER(Test58Rank,Test58Rank[Client]=EARLIER(Test58Rank[Client])),Test58Rank[Sales],Test58Rank[Sales],DESC)

image.png





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




View solution in original post

9 REPLIES 9
LivioLanzo
Solution Sage
Solution Sage

I guess you wanna do it as a calculated column:

 

Ranking = 
    VAR Sls = Sales[Sales]
RETURN
    CALCULATE(
        RANKX( 
            Sales, 
            Sales[Sales],
            Sls
        ),
        ALLEXCEPT( Sales, Sales[Cliente] )
    )

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

Hi! thanks ! but the formula has something wrong
I got the error "A single value form column 'Sales' in the table 'Sales' cannot be determined. This can happen when a measure formula refers to a column that contains many values without an aggregation such as min, max, count or sum to get a single result'

 

I tryed to agreggate the sales by SUM but got nothing out of the formula. 

What should I do? 

@aquanr18

 

are you using the formula in a measure or calculated column ?

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

I have try both, in the measure i got the previus error, 

If I use a calculated the error is 'Function 'RANKX' dose not support comparing values of type text with values of type integer, consider using the value or format function to convert one of the values' 

@aquanr18

 

can you post the table on which you apply this formula via a calculated column

 

 

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

@aquanr18 Please try this as a "New Column"

 

Top = RANKX(FILTER(Test58Rank,Test58Rank[Client]=EARLIER(Test58Rank[Client])),Test58Rank[Sales],Test58Rank[Sales],DESC)

image.png





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




Thanks ! this is exactly what I wanted, may you explain how does the formula work? 

@aquanr18 That's cool !!

 

Just to make it simple - If you are from SQL background, It is just similar to RANK() OVER() along with PARTITION BY. 

So here we want to rank for each group (in this case client) that's why we have nested the FILTER particular client records (each group) and then assigning a rank. To identify current row group, EARLIER function came into picture. That is it.... May be official Microsoft Documentation will explain it better





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




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.