Forum Discussion
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:
| Service | Insurer | Client-code | Cost Total | Min or max per customer |
| Group | A | 20 | 1.436,31 | 4.773,76 |
| Consult | A | 20 | 1.400,45 | 4.773,76 |
| Stay | A | 20 | 1.937,00 | 4.773,76 |
| Consult | B | 145 | 29,21 | 490,13 |
| Stay | B | 145 | 460,92 | 490,13 |
| Group | B | 169 | 749,70 | 749,70 |
| Stay | C | 252 | 1.085,36 | 1.085,36 |
| Consult | B | 582 | 357,29 | 415,71 |
| Stay | B | 582 | 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:
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).
| Service | Insurer | Client-code | Cost Total | Min or max per customer | Duplicate |
| Group | A | 20 | 1.436,31 | 4.773,76 | 1 |
| Consult | A | 20 | 1.400,45 | 4.773,76 | 0 |
| Stay | A | 20 | 1.937,00 | 4.773,76 | 0 |
| Consult | B | 145 | 29,21 | 490,13 | 1 |
| Stay | B | 145 | 460,92 | 490,13 | 0 |
| Group | B | 169 | 749,70 | 749,70 | 1 |
| Stay | C | 252 | 1.085,36 | 1.085,36 | 1 |
| Consult | B | 582 | 357,29 | 415,71 | 1 |
| Stay | B | 582 | 58,42 | 415,71 | 0 |
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)?
1 Reply
- amitchandak
Super User
Anonymous , Based on what I got. The blog from Matt should help you in this case