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
jaak198
New Member

Rank based on aggregate spend

Hi, 

 

Below is a dummy table which summarises the data I am using. 

 

VillageCustomer codeSpendTotal spend by CustomerRank
A10110015001
A10120015001
A10130015001
A10140015001
A10150015001
A1021007002
A1021507002
A1022007002
A1022507002
A1031001005
A1042002004
A1053003003
A1063003003
A1073003003
B201110065001
B201120065001
B201130065001
B201140065001
B201150065001
B202110047002
B202115047002
B202120047002
B202125047002
B203110011005
B204120012004
B205130013003
B206130013003
B207130013003

 

Now the problem that I am having is that I want to be able to rank the Customers by their total spend and I need to be able to rank this by Village. I have managed to do this using a combination of RANKX and FILTER, however, the problem I am having is that when the total spend amounts are the same (as for customers 105, 106, 107, 205, 206 & 207) then it gives the customers the same rank. I want it to give those customers a different rank. If I change my rank setting from "dense" to "skip" then that screws up my ranking at the top with all the rank 1's. 

 

Ideally what I want is to be able to rank by total spend, by village, and when the spend amounts are the same to then use the customer code as the tie breaker. I don't care which of the ties get ranked above the other but just that they are given a different rank.

 

I have see a couple of solutions using RANKX and DIVIDE however I couldn't get them to work to give me the correct results. 

 

Apologies if such topics have already been covered but I am a "newbie".

 

Ali 

2 REPLIES 2
v-sihou-msft
Employee
Employee

@jaak198

 

I assume you create a rank measure:

 

rank =
RANKX (
    ALLEXCEPT ( Table8, Table8[Village] ),
    CALCULATE (
        SUM ( Table8[Spend] ),
        ALLEXCEPT ( Table8, Table8[Village], Table8[Customer code] )
    ),
    ,
    DESC,
    DENSE
)

33.PNG

 

Since your logic should be based on the Spend only, if you need to have different rank for customers with same Spend, your rank is based on customer code as well.

 

Currently, it's not possible to directly make a rank measure/column primary based one column and secondary based on another column. You may create a calculated table to group the Sales together first, then apply condition to achieve this kind of logic.

 

Regards,

Hi,

 

Thanks for your solution however I received the below error message when I tried to run the calculation:

 

A circular dependency was detected: 'Customer'[Calculated Column 1],'Customer'[Calculated Column 1],'Customer'[Calculated Column 1].

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.