Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago

Top x% and Percentile with duplicate values

Good morning All,

 

Background data:

Service: A unique customer can have a different types of services.  

Insurer: A unique customer is always linked with one insurer

Client-code: The client-number is unique for each client, but can appear more than once in the data set if the customer has been provided multiple services (for each service type there is one line-item in the data). 

Cost Total: That is the total costs incurred for the respective customer, for the respective service.

Min or max per customer: This is the total costs-incurred for the respective customer, taking into account ALL services. For this I have used the following Measure: 

 
Min or max per customer = CALCULATE(sum(Title[Cost Total]),ALLEXCEPT(Title,Title[Client-code]))

 

ServiceInsurerClient-codeCost TotalMin or max per customer
GroupA20         1.436,31                              4.773,76
ConsultA20         1.400,45                              4.773,76
StayA20         1.937,00                              4.773,76
ConsultB145               29,21                                  490,13
StayB145            460,92                                  490,13
GroupB169            749,70                                  749,70
StayC252         1.085,36                              1.085,36
ConsultB582            357,29                                  415,71
StayB582               58,42                                  415,71

 

From the data I am trying to develop a table/graph with the following information:

 

1. The average costs per client, per insurer, for their top 5% of clients.

2. The 25, 50, 75 percentile, per insurer.

 

1. The average costs per client, per insurer, for their top 5% of clients.

For this to work I would need to calcululate:

A. The number of unique clients per insurer

 

For this I was thinking on useing the measure:

Unique Clients = DISTINCTOUNT(Title[Client-code])

 

In the graph itself I can add the filter Insurer. I have tested this and that works.

 

B. 5% of unique clients per insurer

 

Note: this is 5% of the total numbers of client NOT 5% of the total cost for an insurer. For example of an insurer has 2.000 unique clients I want to select 5% * 2.000 = their top 100 clients.

 

For this I was thinking on useing the measure:

Top 5% = ROUND([Unique Clients]*0.05,0)

 

In the graph itself I can add the filter Insurer. I have tested this and that works.

 

C. Select the top 5% of clients per customer per insurer and sum their "Min or Max per Customer".

 

And this is where I run into a problem. I am trying to use TOPN er RANKX, but because the data set has multiple line-items for each indidivudal customer (which need to stay in the data set) I can not seem to get it to work. 

 

My preference would be to add a column to the data set that gives a 1 to each unique value and a 0 if that value already eixsts (see example below). This would help me to filter the data and exclude the duplicates (because the same problem occurs for the percentile measure).

 

However I tried to fin a solution for this online but have been unable to find how to do this (e.g. add the 1 and 0 based on unique values).

 

ServiceInsurerClient-codeCost TotalMin or max per customerDuplicate
GroupA20         1.436,31                              4.773,761
ConsultA20         1.400,45                              4.773,760
StayA20         1.937,00                              4.773,760
ConsultB145               29,21                                  490,131
StayB145            460,92                                  490,130
GroupB169            749,70                                  749,701
StayC252         1.085,36                              1.085,361
ConsultB582            357,29                                  415,711
StayB582               58,42                                  415,710

 

D. Calculate the average cost per unqiue client per insurer for their top 5%.

 

Since I have been unable to solve C I have not tried step D as yet. But my thoughts on that so far are for the measure are:

 

Outcome C / Top 5% (e.g. ROUND([Unique Clients]*0.05,0)

 

Your help on the above would be highly appreciated. Hopefully once I have the answer to C (and D) that this will help me to work out the percentile per insurer as well.

 

One more add-on question: Currently I am applying the disclosure per insurer in the graphs itself (by adding it to the x/y-axis). Is this recommended or are their better solutions for displaying it per insurer (for example by embedding this info in the formula)?