Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
hhoward8
Frequent Visitor

weighted average

Hi everyone!

I'm trying to create a type of average. The example in excel is as shown:

 

Payment Receiving   
Day BucketsDaysAmountDays*Amount
1-3030  $                               -  
31-6060 $     8,265.73 $              495,943.80
61-9090 $   17,199.23 $           1,547,930.70
91-120120 $         959.74 $              115,168.80
121-150150 $     1,324.25 $              198,637.50
151-180180 $     5,953.75 $           1,071,675.00
181-210210 $     1,175.15 $              246,781.50
211-240240 $         812.06 $              194,894.40
241-270270 $         218.32 $                58,946.40
271-300300 $         834.27 $              250,281.00
301-330330 $         423.02 $              139,596.60
331-360360 $           42.96 $                15,465.60
361-390390  $                               -  
481-510510  $                               -  
601-630630  $                               -  
721-750750  $                               -  
 TOTAL $   37,208.48 $           4,335,321.30
 AVERAGE            116.51 

 

 

I'm trying to get to the AVERAGE value that is created at the bottom. The issue is, I'm trying to show this Average for of our Top N (10) payers in a single table, alongside their total payments, and the weight of their total payments for the ALL payers (not just top N). i.e.:

 

 

PayerAvg Days to PayTotal PaymentsWeight
Example Co. 116.51 $           37,208.480.11%
Big Bank 64.8 $           46,928.542.93%
Imaginary Store 109.7 $           40,663.510.13%

 

The charges are in buckets per a date difference calculated between when a good is sold and payment is received. So the Charges for that "bucket" is the total charges for that payer in that timeframe. Does anyone have any guidance on how best to do this? I'm connected to SSMS and the table includes a large amount of data (>2M rows).

 

 

"Payments" is measure in the table that this is all calulcated off of. Right now Date Diff is calculated as:

 

DateDiff = DATEDIFF([Date Sold],[Date Paid],DAY) and returns a whole number. 

 

Buckets is calculated as:

 

Buckets = IF(Table[DateDiff] < 31, 30, IF(
Table[DateDiff] < 61 && Table[DateDiff] > 30, 60, IF(
Table[DateDiff] < 91 && Table[DateDiff] > 60, 90, IF(
Table[DateDiff] < 121 && Table[DateDiff] > 90, 120, IF(
Table[DateDiff] < 151 && Table[DateDiff] > 120, 150, IF(
Table[DateDiff] < 181 && Table[DateDiff] > 150, 180, IF (
Table[DateDiff] < 211 && Table[DateDiff] > 180, 210, IF(
Table[DateDiff] < 241 && Table[DateDiff] > 210, 240, IF(
Table[DateDiff] < 271 && Table[DateDiff] > 240, 270, IF(
Table[DateDiff] < 301 && Table[DateDiff] > 270, 300, IF(
Table[DateDiff] < 331 && Table[DateDiff] > 300, 330, IF(
Table[DateDiff] < 361 && Table[DateDiff] > 330, 360))))))))))))

3 REPLIES 3
v-xjiin-msft
Solution Sage
Solution Sage

Hi @hhoward8,

 

=> I'm trying to show this Average for of our Top N (10) payers in a single table.

 

How could we know which payers are the top N? Does there exist a sequence column?

 

Generally to get top n rows in Power BI, we can use RANKX() function to make an order. Let's make a sample based on your sample data to get top 10 rows total amount and average amount.

 

You can use RANKX() function to make an order.

 

Rank =
RANKX ( Table1, Table1[Days],, ASC, DENSE )

Then use this Rank to get top 10 total amount and average amount.

 

Top 10 total amount =
CALCULATE ( SUM ( Table1[Amount] ), Table1[Rank] <= 10 )


Top 10 days =
CALCULATE ( MAX ( 'Table1'[Days] ), Table1[Rank] = 10 )


Top 10 average =
[Top 10 total amount] / [Top 10 days]

1.PNG

 

Thanks,
Xi Jin.

Hi @hhoward8,

 

Yes. TOPN() function is better than RANKX() in your scenario.

 

=> The issue is, I'm trying to show this Average for of our Top N (10) payers in a single table, alongside their total payments, and the weight of their total payments for the ALL payers (not just top N).

 

So you want to calculate the average just for the top N payers. However the weight should be based on all payers. Right? 

 

Could you please share us a sample pbix file with multiple payers source data if possible? Since your current sample data is only for one payer and we don't know your source table structure. It is hard for us to provide a proper solution.

 

Thanks,
Xi Jin.

Hi @v-xjiin-msft,

 

The Top 10 are currently being shown by using the Top N filter in the built in function. I filter the Payer Name by Payments (i.e. whoever pays the most is shown), so there is no need for a rank function unless this filter method does not work properly (right now it does, though). 

 

Thanks,



Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.