Conditional correlation formula in Excel - excel-formula

I'm trying to calculate the correlations for the funds below. The below example is simplified example and in reality there are more than 100 funds. Is there a formula which would allow me to calculate the correlation conditional on the Fund.
I have already tried using the a formula combining "CORREL" and "IF" but doesnt work. The correlation for Fund A and Benchmark should be 1.0, not -0.23.
The -0.23 correlation corresponds to ALL fund returns vs benchmark returns, not an individual fund.
When exiting the formula using Ctrl-shift-enter, the correlation is calculated correctly for the first fund. However, the formula fails to calculate the correlation for the two remaining funds:

Related

Invoice total in row n, payment in row n+k, using dates

I have a table of payments to calculate interest. The column where the payment is applied takes its values from the column where the invoice totals are listed, however, the payment is applied k days after the period ends.
I had partial success doing it using this formula:
IFERROR(INDEX($F$12:$F$25,MATCH(D12,$G$12:$G$25,1)),0)
Where column G is a helper column with the dates of payment, basically period end + k, but since it only accounts for the period end, in monthly and semimonthly periods, sometimes the nearest lower date of payment was on the same period, so I MUST also account for the period start for this to not happen. I've been helped using an array formula like this:
=IFERROR(INDEX(F:F,SMALL(IF(F$12:F12>0,ROW(F$12:F12)),COUNT(1/((C$12:C12-C$12>C$7)+(D$12:D12-C$12>C$7))))),0)
And it works well and it does not require a helper column. But since it's an array formula, and this table is not for my usage, that's not suitable.
I would like to know if I can do this without an array formula and built-in excel 2013 functions.
Edit:
This formula does it:
=SUMPRODUCT(($D$12:$D$25+$C$7>=C12)*($D$12:$D$25+$C$7<=D12)*($F$12:$F$25))
But if there are blanks in column D that result from a formula, it returns an error. So the following formula is more stable:
=SUMIFS($F$12:$F$25,$D$12:$D$25,">="&C12-$C$7,$D$12:$D$25,"<="&D12-$C$7)
This one effectively places the payment rows within the range of dates it belongs to.
At least you can replace SMALL with AGGREGATE like this:
=IFERROR(INDEX(F:F;AGGREGATE(15;6;(ROW(F$12:F12)/(F$12:F12>0));COUNT(1/((C$12:C12-C$12>C$7)+(D$12:D12-C$12>C$7)))));0)
AGGREGATE(15;6;;) is the same as SMALL, but it ignores errors. This lets you switch out the IF(F$12:F12>0,ROW(F$12:F12)) for the quotient (ROW(F$12:F12)/(F$12:F12>0)). Every row-number divided by a FALSE produces an error which gets ignored by AGGREGATE.
For the COUNT-part I cannot say, what it is doing, as my results don't look like yours (i copied your formula).
I guess it works as an offset.
Can you test my formula and tell me if it is working without cse? Else we need to find a replacement for the COUNT-part. I currently cant test it as I am on Office 365 and don't know if i can activate the old CSE-functionality.

Excel - Direct excel formula to calculate sum of product of deviations from the mean for 2 arrays x & y (without squaring)

Is there a direct excel formula to calculate sum of product of deviations from the mean for 2 arrays, x & y (without squaring)
Here is the formula:
I already know how to use SUMPRODUCT to get the result.
SUMPRODUCT(rng1 - avg(rng1), rng2 - avg(rng2))
I want to know if there is a direct formula such as SUMXMY2 function
which gives the following sum :
As far as I know, the short answer is 'no' - the nearest function is Covariance.P
according to Microsoft's documentation
so you have to multiply by the number of data pairs in the range to get the answer you want e.g.
=COVARIANCE.P(A2:A6,B2:B6)*COUNT(A2:A6)
using the data in the above reference.
Looking at this in a bit more detail, the Sumproduct formula produces incorrect results if there are missing data items in one or both columns because it treats them as zeroes so should probably be deprecated unless the user is confident of having complete data.
To allow for missing values in either column, the formula above should be changed to:
=COVARIANCE.P(A2:A6,B2:B6)*COUNTIFS(A2:A6,"<>",B2:B6,"<>")

Excel SUMIFS question: multiple criteria’s with AND?

Novice Excel user here. I am trying to figure out to solve a bit of an Excel SUMIFS pickle. I am trying to total all the revenue of 8 cost centres from a particular revenue account with a particular description. The data has multiple cost-centres from different divisions, so that revenue would not assist with my reconciliation process.
So my question is, is there a way to add multiple criteria in one of the criteria boxes for example cost centre 2965 AND 1955 AND 2344 AND 3966 AND.... instead of doing it the way I have done below, which is so big and confusing:
“ =-SUMIFS($L:$L,$C:$C,Q11,$B:$B,$Y$6,$E:$E,"Fleet Distribution Revenue")+-SUMIFS($L:$L,$C:$C,Q11,$B:$B,$Y$7,$E:$E,"Fleet Distribution Revenue")+-SUMIFS($L:$L,$C:$C,Q11,$B:$B,$Y$8,$E:$E,"Fleet Distribution Revenue")+-SUMIFS($L:$L,$C:$C,Q11,$B:$B,$Y$9,$E:$E,"Fleet Distribution Revenue")+-SUMIFS($L:$L,$C:$C,Q11,$B:$B,$Y$10,$E:$E,"Fleet Distribution Revenue")+-SUMIFS($L:$L,$C:$C,Q11,$B:$B,$Y$11,$E:$E,"Fleet Distribution Revenue")+-SUMIFS($L:$L,$C:$C,Q11,$B:$B,$Y$12,$E:$E,"Fleet Distribution Revenue")+-SUMIFS($L:$L,$C:$C,Q11,$B:$B,$Y$13,$E:$E,"Fleet Distribution Revenue")”
The Cell Y is the reference to each of the eight cost centres, so I have to do the SUMIF 8 times, which is ridiculous. Is there a better way?
With classical Sumifs, you are using the correct approach.
If you have Office 365, you can use the new Filter() function, to filter the data with different criteria. AND logic is done with a * and OR logic is done with a + sign.
What you describe as "AND" is really "OR" logic, since a cell can only have one value.
Here is a simplified scenario:
=SUM(FILTER(A:A,((B:B=E2)+(B:B=E3)+(B:B=E4)+(B:B=E5)+(B:B=E6))*(C:C="x")))
In words: Sum all values from column A where column B is equal to either E2 OR E3 OR E4 OR E5 OR E6 and where column C is equal to x

Skip certain calculated values (not cells themselves) in an AVERAGE or STDEV Excel formula based on a criterion

I have a series of paired measurements (two for each sample). I need to calculate the mean for each pair and then the general mean based on those pairwise averaged values, but I can only include those pairwise means that don't exceed a certain threshold.
I'm trying to work out an excel formula for the general mean that takes into account all of the above, without having to create additional rows/columns.
Now, the formula
=AVERAGE(IF(ABS(A1-A2)<$C$1,AVERAGE(A1,A2)),IF(ABS(A7-A8)<$C$1,AVERAGE(A7,A8)), ... )
... doesn't do the job because it replaces with zeros those pairwise means that exceed the threshold (value of $C$1), while they just need to be skipped. "AVERAGEIF" doesn't work because it doesn't accept non-contiguous ranges (at least when they are entered as such), using "INDIRECT" to build non-contiguous ranges doesn't help either because it doesn't accept formulas. Any help appreciated.
Not using helper column here is making formula look ugly but will give you the desired result. Have a try.
=AVERAGE(IF(CHOOSE({1;2;3},A1-A2,A4-A5,A7-A8)<C1,CHOOSE({1;2;3},AVERAGE(A1,A2),AVERAGE(A4,A5),AVERAGE(A7,A8))))
This is an array formula so commit it by pressing Ctrl+Shift+Enter.
See image to see the difference in the result from above formula and formula in question that is yielding incorrect result as you mentioned.
This is where Excel has some mysterious behaviour I think.
My first thought was to make each if statement return "" if the condition wasn't satisfied
=AVERAGE(IF(ABS(A1-A2)<$C$1,AVERAGE(A1,A2),""),IF(ABS(A7-A8)<$C$1,AVERAGE(A7,A8),""))
but this just gives you an error.
However, if you make it return a reference to an empty cell (say B1) it works fine
=AVERAGE(IF(ABS(A1-A2)<$C$1,AVERAGE(A1,A2),$B$1),IF(ABS(A7-A8)<$C$1,AVERAGE(A7,A8),$B$1))

EXCEL calculating average with OFFSET (coord unspecified) of a given keyword

Fun situation I'm trying to calculate. Basically in one row I have names of products, and the row to the right of it the number of days that have passed since the product was first received.
The calculation to do the days for ex is
=TODAY()-BB2
What I'm trying to do NOW, is identify let's say the product word "truck," and then calculate how many days on average the holding time of truck is.
I understand the logic of the formula I need, just not how to execute precisely. Basically the formula is going to need to use this average calculator with a keyword identified COUNTIF
=COUNTIF($A$2:$A$900,"TRUCK")/COUNTA($A$2:$A$900)
What I'm missing is some type of...IF "TRUCK, OFFSET (GIVEN CELL) -1)
Thanks for any thoughts!
-Wilson
A formula (in C1 in the example):
=AVERAGEIF(A:A,"truck",B:B)
should work but I would recommend a PivotTable for the additional functionality it provides:

Resources