Discussion

1
Replies
512
Views
Otto Perdeck (Otto_Perdeck)
PEGA
Director, Data Science
Pegasystems Inc.
NL
Otto_Perdeck Member since 2010 9 posts
PEGA
Posted: April 11, 2016
Last activity: April 12, 2016
Posted: 11 Apr 2016 6:49 EDT
Last activity: 12 Apr 2016 3:20 EDT
Closed

What is the preferred way to create a weighted average in reports?

Hi,

What is the best way to create a weighted average in a report definition? The aggregation functions include Sum, Min, Max, Average but there is no weight field. 

Imagine I have data like this

ITEM PRICE QUANTITY
A 10 25
  5 100

I want to have the average price weighted by quantity, per item.

The average price is 7.5, the weighted average should be (10*25 + 5*100)/(25 + 100) = 6.

In SQL, this would be something like

SELECT ITEM, SUM(QUANTITY*PRICE)/SUM(QUANTITY)
  FROM <TABLE>
GROUP BY ITEM

How do I accomplish that best in a report def?

Thanks

Otto

 

 

Reporting
Moderation Team has archived post, This thread is closed to future replies. Content and links will no longer be updated. If you have the same/similar Discussion, please write a new Discussion.