Calculate correlation in Excel after matching on a column - excel

I need to calculate correlations for multiple years. The trick is in selecting appropriate rows from 2 columns after matching values a third column.

Use the CORREL() formula as an array formula:
=CORREL(IF($A$2:$A$12 = E2,$B$2:$B$12),IF($A$2:$A$12 = E2,$C$2:$C$12))
Being an array formula it needs to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.

Related

In Excel, how to find a average from selected cells

Need your help.
I have an excel sheet with two columns, like this:
I would to find an average of the number in the cells from column 2 that correspond to the numbers in column 1 which end either in 2 or 5. If column 2 has a blank cell or a letter, it should be ignored.
If one has the dynamic array formula FILTER():
=AVERAGE(FILTER(B2:B15,ISNUMBER(MATCH(--RIGHT(A2:A15),{2,5},0))))
If not then use this array formula:
=AVERAGE(IF(ISNUMBER(MATCH(--RIGHT(A2:A15),{2,5},0)),B2:B15))
Being an array formula it needs to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.

Array formula without some rows

I have a question about an array formula. I want to a formula but not get the values for some rows.
I now have this array formula working: =IFERROR(INDIRECT(ADDRESS(SMALL(IF($H$7:$H$59>0,ROW($7:$59),""),ROW(A1)),1)),"")
I want to use this formula but only show the values from rows 7:36 and rows 40:59.
How can I adjust the formula to make it return only the values from these rows above? The rest of the formula is working fine.
First INDIRECT and ADDRESS are Volatile. Replace them with INDEX:
Your current formula non-volatile:
=IFERROR(INDEX(A:A,SMALL(IF($H$7:$H$59>0,ROW($7:$59),""),ROW(A1)),"")
Next we can add some more criteria to the IF to ignore those rows:
=IFERROR(INDEX(A:A,SMALL(IF(($H$7:$H$59>0)*((ROW($H$7:$H$59)<=36)+(ROW($H$7:$H$59)>=40)),ROW($7:$59),""),ROW(A1)),"")
Still an array formula that must be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.

Formula for comparing multiple cells with random values in excel and return conditional output

I need a formula to perform below operation in MS excel. Here is the scenario:
My case is I have to compare 4 cells in a single row. 3 of the cell values are similar and 1 will be unique always. They can be in random sequence but there will be an unique value and 3 duplicate values while comparing 4 cells. As you can see in the result column, I need the output which is the unique value. Please help me to write the formula.
If your cells contain only numbers, here's an approach using SUMIF and MODE.SINGL
=SUMIF(A2:D2,"<>"&MODE.SNGL(A2:D2))
For text or numbers, you can use an array formula - enter with Ctrl + Shift + Enter.
=INDEX(A2:D2,MATCH(MIN(COUNTIF(A2:D2,A2:D2)),COUNTIF(A2:D2,A2:D2),0))

I need to find an excel formula that I can use to create a unique list of Item numbers from an array

I need to find an excel formula that I can use to create a unique list of Item numbers from an array. I do not want to count them I just want to make a list of the Item Numbers. These part numbers are actually Alpha Numeric and can have repeating numbers through out the array multiple times. There is one other catch this list will have empty cells in it and could also be the first record in the array. This data is being pulled into Excel through a Jet report add-in for Excel.
Example: Starting in cell A1..A9
Item No.
<BLANK>
7810042050
783979
7810006045
7810006042
7810006032
<BLANK>
7810006022
7810006032
With values in column A, in C1 enter:
=MAX(A1:A10)
in C2 enter the array formula:
=MAX(IF(A$1:A$10<C1,A$1:A$10,""))
and copy down:
Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key.
EDIT#1:
Chris Neilsen has pointed out that the values in column A are actually Text rather than Numeric. To accommodate this, two changes must be made to the formulas:
A1 must be excluded
the alphas must be converted to numeric.
So we will replace the normal formula:
=MAX(A1:A10)
with the array formula:
=MAX(--(A2:A10))
and replace:
=MAX(IF(A$1:A$10<C1,A$1:A$10,""))
with the array formula:
=MAX(IF(--(A$2:A$10)<C1,--(A$2:A$10),""))
and then copy down.
If you have alpha characters in the part numbers you can do this in 2 steps.
Both are array formulas and you need to use Ctrl-Shift-Enter
Col B - sorted list of items in Col A
B2 =IFERROR(INDEX($A$2:$A$10,MATCH(COUNTA($A$2:A2),COUNTIF($A$2:$A$10,"<="&$A$2:$A$10),0),1),"")
Col C - eliminate the duplicates
C2 = IFERROR(INDEX($B$2:$B$10, MATCH(0, COUNTIF($C$1:C1, $B$2:$B$10), 0)),"")
Copy both formulas down.
I tried to combine the two formulas but nesting an array (results in Col B) with varying row ranges did not work out. I could not find a way but the two formulas together will work.
Enter this Formula Array in B2 and copy to B3:B10
FormulaArrays are entered pressing [Ctrl] + [Shift] + [Enter] simultaneously, you shall see { and } around the formula if entered correctly
=IFERROR(
INDEX($A$2:$A$10,
MATCH(1,1+COUNTIF($B1:$B$1,$A$2:$A$10)+(($A$2:$A$10="")*1),0)*1),"")

Get the maximum values of column B per each distinct value of column A

I have an Excel spreadsheet of the form:
A,B
X,1
X,5
Y,4
Y,11
X,7
Z,1
I would like to get the maximum value of column B for each distinct value of column A - how can I do it via pure Excel formula?
Desired result (order is irrelevant):
A,B
Y,11
X,7
Z,1
In other words, I would like Excel's version of an SQL query
SELECT A,max(B)
FROM myTable
GROUP BY A
Any version of Excel is acceptable, but I use 365 one.
Pivot tables are an acceptable approach (I currently did it with a pivot myself) but I would strongly prefer a real formula - the main goal of the question is to enhance my understanding of formula programming in Excel. No VBA
Gary's Student's answer is correct. I added a couple things.
Also, a link to the method:
http://blog.contextures.com/archives/2011/07/27/finding-min-if-or-max-if-in-excel/
A distinct list of values can be generated in a couple ways, here's one:
And here's links to a method or two for distinct lists. All with array formulas:
Ignore Duplicates and Create New List of Unique Values in Excel
Getting unique values in Excel by using formulas only
With data in columns A and B use the Array Formula:
=MAX(IF(A1:A6="x",B1:B6))
Same for "y" and "z"
Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key.
Notice the braces in the Formula Bar
EDIT#1:
To generate the formulas automatically, first copy column A to column C.
Then use the Remove Duplicate feature in the Data tab:
Then enter the Array Formula in cell D1:
=MAX(IF(A$1:A$14=C1,B$1:B$14))
and copy down:
The formula is only entered once and then copied down!
Pivot table is the correct answer.
Select column A's title and drag it to the Row Labels section.
Select column B's title and drag it to the Values section.
Click the arrow on column B's title in the values section and choose Value Field Settings.
Select Max
Try below. Note I moved your desired output table to Columns D and E. You will not need to hard-code any values into formulas.
Data
D E
Y 11
X 7
Z 1
Formulas
E2 Formula: ={MAX(--($D1=A1:A6)*B1:B6)}
E3 Formula: ={MAX(--($D2=A2:A7)*B2:B7)}
E4 Formula: ={MAX(--($D3=A3:A8)*B3:B8)}

Resources