Excel: Trying to consolidate weighted average data from Sheet1 and summarize to Sheet2 when Sheet 1 has variable number of rows - excel-formula

I can't figure out how to get formula to recognize variable # of rows for each weighted average calculation in a single, replicable formula combination. I've tried (and failed) to use combinations of sumproduct / address / match / offset / countif / if / etc. I feel like this should be super easy, but I'm stumped.
Sheet1 has variable number of rows for each CompanyX/Y/Z
Value Weight
CompanyX DataA DataA1
CompanyX DataB DataB1
CompanyX DataC DataC1
CompanyY DataN DataN1
CompanyZ DataU DataU1
CompanyZ DataV DataV1
But I want to summarize weighted average with at Company level e.g.
Weighted Average
CompanyX ResultABCA1B1C1
CompanyY ResultNN1
CompanyZ ResultUVU1V1
Can't get there from here...help!

I believe you need a pair of SUMPRODUCT calls. The first is to get the product of value and weight for a company. The second is to just get the sum of the weights for a company. The first term in this formula is used to check that the company matches (it returns 0 or 1 with the --); the second and third terms are for the weighted average math.
Array formula (enter with CTRL+SHIFT+ENTER) in cell G3, copied down from there, see picture for other ranges.
=SUMPRODUCT(--(F3=$B$3:$B$8),$C$3:$C$8,$D$3:$D$8)/SUMPRODUCT(--(F3=$B$3:$B$8),$D$3:$D$8)
Ranges and result

Related

How to calculate average rating in excel with excluding blank cells?

How to calculate average rating in excel with excluding blank cells?
In other way
if cells is empty --> not calculate rating
if 0 or greater than 0 to 5 --> calculate rating
then calculate average ratings.
Do you mean that your range includes values of less than 0 and/or larger than 5 and empty, but you only want to calculate value from 0 to 5?
I think you'd better use pair of SUMIFS and COUNTIFS, with set of your conditions (>=0, <=5, not blank...).
For example, assumed your value range B1:B6:
=SUMIFS(B1:B6,B1:B6,">=0",B1:B6,"<=5")/COUNTIFS(B1:B6,">=0",B1:B6,"<=5")
This give out result of average of 2.5
And please note that COUNTIFS or AVERAGE... they do not count empty cells by default.

Finding average but with a maximum value per cell in excel

I am trying to find the average of a range of cells that fall between a predefined/criteria range (i.e. 0-2) but treating the end of the range (2 - in this example) as the maximum amount to be used in calculating the average over the range of cells in excel.
Here is an example of the data I am interested finding the average for:
COST
2
3
5
7
If finding the average using the range of 0-2, it should be 2, as you'd be treating anything with the cost of 2+ as 2. So, the total is 2+2+2+2=8 and there are 4 cells so the average would be 2.
Another example would find the average using the range of 0-3, the average would be 2.75, as the first value in the above table falls between the criteria range and the rest match or fall outside the high end of of range so they are assigned the maximum of 3. So, the total is 2+3+3+3=11 and there are 4 cells so the average would be 2.75.
You can try:
=SUM(IF(A2:A5>=C2,C2,A2:A5))/COUNT(A2:A5)
in pre-O365 it must be entered as array formula with Ctrl+Shift+Enter

Excel Formula to calculate Average rating out of 5

I have a table of data where ratings are given as V good - 3, Good - 2, Avg - 1 but if the value is NA I want to exclude that from Avg.
I do have values stored as Good, V Good, Avg against the record.
Any excel formula for this to calculate rating out of 5.
Thanks in advance.
Please try this formula. It's designed for entry in a cell in row 2 from where it can be copied down.
=IFERROR(SUMPRODUCT((COUNTIF(C2:E2,{"V Good","Good","Avg"})*{3,2,1}))/SUMPRODUCT((COUNTIF(C2:E2,{"V Good","Good","Avg"}))), "NA")
There are only 3 columns in your example. Therefore I don't understand your request for a "rating out of 5". However, you can use the same formula on a larger range, of 5 or more columns. Just change both range references to include more columns, like E2:G2. The important thing is to change both to the same size of range.

How to create a dynamic formula to find the average of a set of values for a given vector

I am trying to create a formula that gives me the average of the last 12 entries in a given dataset depending on the associated vector.
Let's make an example:
I have in column F2,G2,H2 and I2 dates, Company1, Company2 and Company3 respectively. Then from row3 to row 33 I have months dates starting from May 2016.
Date Company1 Company2 Company3
May-16 2,453,845
Jun-16 13,099,823
Jul-16 14,159,037
Aug-16 38,589,050 8,866,101
Sep-16 63,290,285 13,242,522
Oct-16 94,005,364 14,841,793
Nov-16 123,774,792 7,903,600 41,489,883
Dec-16 93,355,037 12,449,604 69,117,105
Jan-17 47,869,982 13,830,712 83,913,764
Feb-17 77,109,905 10,361,555 68,176,643
The goal is to create a formula that, when I drag it down, correctly calculates the average of the last 12 values for a given company.
So for example i would have, say in table "B2:C5":
Company1 76,856,345
Company2 11,120,859
Company3 65,674,349
And, if a new Company4 is added to the list, then I just have to drag it down the formula, to calculate the average of the last 12 months for Company4.
Until now, I have came up with this formula:
=AVERAGE(LOOKUP(LARGE(IF(ISNUMBER(G:G),ROW(G:G)),ROW(INDIRECT("1:"&MIN(12,COUNT(G:G))))),ROW(G:G),G:G ))
This formula correctly calculates the average of a given column, considering only the last 12 values. The last step would be to come up with a formula that includes all the columns and then calculates the average for the given company.
Thanks!
I recommend that you use a named range to define your data in columns G:I. When a company is added, just modify the named range's specs. I used the name Target. Of course, you can replace it with $G:$I if you feel so inclined but I would rather recommend reducing the number of rows in the range, which is easier to manage when it is named.
Use the formula below to extract the company names from the first row of Target into the first column of your averages table. This is to ensure that the names are spelled identically in both locations.
=INDEX(Target,1,ROW()-2)
The number 2 indicates the number of rows above the row containing the formula. it is copied here from cell M3. There, ROW()-2 creates the number 1, counting sequentially as the formula is copied down.
Now I have the formula below in my cell N3 and copied down.
=SUM(INDEX(Target,0,MATCH($M3,INDEX(Target,1,0),0)))
The formula simply sums up the columns G, H, and I in 3 consecutive rows.
In the final step I inserted the range definition established above, meaning excluding the SUM() function, into your existing formula.
=AVERAGE(LOOKUP(LARGE(IF(ISNUMBER(INDEX(Target,0,MATCH($M3,INDEX(Target,1,0),0))),ROW(INDEX(Target,0,MATCH($M3,INDEX(Target,1,0),0)))),ROW(INDIRECT("1:"&MIN(12,COUNT(INDEX(Target,0,MATCH($M3,INDEX(Target,1,0),0))))))),ROW(INDEX(Target,0,MATCH($M3,INDEX(Target,1,0),0))),INDEX(Target,0,MATCH($M3,INDEX(Target,1,0),0))))

Median Selling Price Excel Table

I have a spreadsheet with different products, listing units and retail value sold like the example below
Product Units Value
A 10 100
B 15 80
C 30 560
I'd like to compare the Average Selling Price with the Median Selling price, so I am looking for a quick formula to accurately calculate the median.
The median function requires the entire series, so for Product A above I would need 10 instances of 10 etc. How can I calculate the Median quickly considering the condensed form of my data?
Without writing your own VBA function to do this there are a couple of approaches that can be taken.
The first expands the data from its compressed frequency count format to generate the full set of observations. This can be done manually or formulaically. On the assumption the latter is required, it can be achieved using a few columns.
All the blue cells are formulae.
Column Eis simply the cumulative of column B and F is an adjusted version of this. Column H is just the values 1 to 55, the total number of observations given by cell L2. Column I uses the MATCH() with its final argument as 1 to match each observation in H against the adjusted cumulative in F. Column J uses the INDEX() function to generate the value of the observation. (Observations 1-10 have value 100, 11-25 have value 80 and 26-55 have value 560 in this example). The MEDIAN() function is used in cell M2 with column J as its argument.
This approach can be refined to take account of varying numbers of products and data points through the use of the OFFSET function to control the range arguments of the MATCH(), INDEX() and MEDIAN functions. And, of course, adjacent cells in columns I and J could be combined using a single formula - I've shown them separately for ease of explanation.
The second approach involves sorting the data by value (so in this case the data rows would become Product B in row 2, product A in row 3 and product C left as-is in row 4). It is then a case of identifying the middle observation number (if the number of observations is odd) or the middle pair of observation numbers (if the number of observations is even) and then determining the value(s) corresponding to this/these middle observation(s). In this approach the adjusted cumulative in column F is still used but rather than explicitly calculating the values in column I and J for every observation it can now be restricted to just the middle observation(s).
I think there is no way around compromises. Either using big amounts of helper cells or having the table sorted by the values.
Helper cells:
Formula in F4:AS6:
=IF(COLUMN()<COLUMN($F$4)+$B4,$C4,"end")
Formula in D2:
=MEDIAN(F4:AS6)
Sorted:
Formula in F4 downwards:
=SUM($B$3:B3)+1
Formula in D2:
=SUM(LOOKUP(INT(SUM(B4:B6)/2+{0.5,1}),F4:F6,C4:C6))/2

Resources