TopN Required

jacobrcotton

Board Regular
Joined
Jan 28, 2017
Messages
51
New Power BI user here, and this is my first project so please go easy on me!

I dont seem to be able to post my Relationships Map directly, so I've loaded them here for viewing: https://paste.pics/54GW8.

I have three FACTs (EnrollmentDetail, ClaimsLineDetail - Paid, ClaimsLineDetail - Incurred) that are all connected via 10ish dimensions (usually labeled as "[Dimension]Key").
*Note, specifically, that the three FACT files contain no uniqueness. IE, all field values can and do appear multiple times on the FACTs.
**The ClaimsLineDetail - Paid and ClaimsLineDetail - Incurred are identical in thier data, but connected to the DateTable via Paid Date and Incurred Date, respectively.

The Claims FACTs separate $ by Medical expenses and Pharmacy Expenses. Two of my measures "TotalPaid" & "Total Incurred" is simply the sum of these two fields via code:
Code:
[COLOR=#000000][FONT=Consolas]TotalPaid = CALCULATE(sum('ClaimLinesDetail - Paid'[Medical Paid])+sum('ClaimLinesDetail - Paid'[Pharmacy Paid]))
TotalIncurred = CALCULATE(sum('ClaimLinesDetail - Incurred'[Medical Paid])+sum('ClaimLinesDetail - Incurred'[Pharmacy Paid]))[/FONT][/COLOR]


I'm trying to
(1) Sum the Medical & Pharmacy into Total Paid (done)
(2) Sum the Total Paid by Member ID (done)
(3) Determine the TopN (2, 5, 10, whatever) Member IDs
(4) Sum the Total Paid of just those TopN Member IDs
(5) Divide the sum of (4) by theGrand Total Paid of all IDs.

To ID my TopN, my measure code is:
Code:
[COLOR=#000000][FONT=Consolas]Top2PaidTest001 = CALCULATE([TotalPaid], TOPN(2, MeasuresTable, [TotalPaid], DESC))[/FONT][/COLOR]

The results I get are clearly incorrect, but I'm not sure why. When I compare the Grand Total Paid against the Top2 Total Paid, I get the exact same number (~$10M, which is the correct amount for the Grand Total Paid).


81e2cab91f83e1a39e65488819fad844
81e2cab91f83e1a39e65488819fad844
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
A few corrections to the original post:

(3) Determine the TopN (2, 5, 10, whatever) Member ID based on Total Paid

I am happy to post my .pbix (de-IDd, of course), if that would help. Is that possible?
 
Upvote 0
(1) "MeasuresTable" is an empty table that i use to store my Measures value for organizational purposes. IE, it lets me find all my measures quickly & in 1 spot.

(2) I want the 2 (or 5, or 10, or whatever) highest because I would like to know how concentrated is my TotalPaid $, in the top 2, 5, 10, whatever number of members. So my first step is identify the Top N spenders and then calculate the % of the Grand Total Spend.
 
Upvote 0
Yeah, but your measure isn’t finding the top 2 spenders, it’s finding the top 2 measures on the measuretable. Look at the second parameter of your TOPN
 
Upvote 0
Ok, so I guess I need my "TotalPaid" measure to actually be a column within the FACT table(s)? Again, my 1st project in Power BI, so if there are basic organizational issues, I'm open to revamping this.
 
Upvote 0
oh man. I'm such an idiot. I was under the impression that the 2nd clause needed to be the table that contained the measure of the 3rd clause.

Your solution worked perfectly.

thank you so much!
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,206
Members
453,022
Latest member
RobertV1609

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top