How do transform a "matrix"-table to one line for each entry in excel - excel

I have something like
1 2 3
a x o x
b x x o
c o o o
and want to transform it into lines like
1 a x
1 b x
1 c x
2 a o
2 b x
2 c o
3 a x
3 b o
3 c o
by using a formula in the excel document. Playing with $ for assigning values for each row and column does give me proper results. Each time I have to do some manual changes to the formula.
Any hint how to write it the right way?

Suppose that your matrix in the cells A1:D4
in A6 put:
=OFFSET($A$1;0;QUOTIENT(ROW()-ROW($A$6);3)+1)
in B6 put:
=OFFSET($A$1;MOD(ROW()-ROW($A$6);3)+1;0)
in C6 put:
=VLOOKUP($B6;$A$1:$D$4;MATCH($A6;$A$1:$D$1;0);FALSE)
Den drag down (copying formulas) A6:C6 up to A14:C14
(I translate my formulas from italian so there could be some glitch)
PS: 3 in the formulas refers to the number of rows (and column) of the example.

I know that it was answer years ago, BUT there is a much easier way to flatten the pivot table. This is also called the unpivot or reverse pivot.
see this:
https://www.youtube.com/watch?v=N3wWQjRWkJc
or this:
https://www.youtube.com/watch?v=pUXJLzqlEPk&list=LLzMcMocJLlJOCteGbfN3xvA&index=2

Related

Return Multiple Unique Matches in Excel without Array Formula

Given an Excel table of shape
Col. A Col B Col. C Col. D Col. E
x 2 x 2 3
x 3 y 7
y 7 z -5
x 2
z -5
I want to return the first unique hit in Column B for argument "x" in Column D,
the second unique hit in Column B for argument "x" in Column E and so forth.
The formula I'm currently using in cell D1 for this is
{=IFERROR(INDEX($B$1:$B$5,MATCH(0,COUNTIF($C1:C1,$B$1:$B$5)+($A$1:$A$5<>$C1),0)),"")}
which is working.
The problem I'm having is that since this is an array formula and since I'm analyzing a decent amount of data computation time for my sheet is too high.
Is there an alternative for this functionality avoiding an array formula?
Thanks!
Haven't got time to test this properly, but if you have Excel 365 you can use a single formula per row and it may be faster:
=TRANSPOSE(UNIQUE(FILTER(B1:B10,A1:A10=C1)))
in D1.
EDIT
To pull the formula down, you need static references as OP has pointed out. Probably should check for empty cells in column C as well, so formula becomes:
=IF(C1="","",TRANSPOSE(UNIQUE(FILTER(B$1:B$10,A$1:A$10=C1))))

average specific values in column

I have two columns in an Excel spreadsheet that look like:
Key Values
f 1
f 2
u 3
g 4
g 5
h 6
h 7
j 8
j 9
k 10
k 11
k 12
Is it possible to create formula which creates an average that uses values that are associated with a specific key? For example if I only wanted to include values for f,u,h, and k only (where the average calculated by hand is: 6.5)?
Unfortunately, I can't use VBA in this instance.
As mentioned by Brad, just use AverageIf() worksheet function:
(In my example I started the first 'f' in cell B2)
=AVERAGEIF(B2:B13;"=f";C2:C13)
Adding all the criteria the provided links show could be quite tedious, here is a way that MAY be simpler. So just as an option:
=SUM(SUMIFS($B$1:$B$12,$A$1:$A$12,{"f","u","h","k"}))/SUM(COUNTIFS($A$1:$A$12,{"f","u","h","k"}))
No need to enter as array formula, which should be an advantage.

Google Sheets - formula to return N first values from range A where MAX(range B)

F1:N1 with random numbers (can have duplicates).
F2:N2 with sorted numbers.
Need a formula to fill in A1:C1 with values from F2:N2 where F1:N1 has a maximum value.
In the example it should be 1,8,3 from F2:N2 - according to 9,9,8 from F1:N1.
_ A B C D E F G H I J K L M N
1 ? ? ? 9 3 8 1 5 5 3 9 8
2 1 2 3 4 5 6 7 8 9
You can do this with a "helper row" to create a list of unique ranks:
F3: =RANK(F1,$F$1:$N$1)+COUNTIF($F$1:F1,F1)-1
and fill right to N3
Since your values in F2:N2 are sequential {1...8}, you can use this formula:
A1: =MATCH(SMALL($F$3:$N$3,COLUMNS($A:A)),$F$3:$N$3,0)
and fill right to C1
If the values in F2:N2 are random, then you can use this:
A1: =INDEX($F$2:$N$2,1,MATCH(SMALL($F$3:$N$3,COLUMNS($A:A)),$F$3:$N$3,0))
and fill right to C1
Nobody has jumped in to offer a Google Sheets solution so here is one:
=query(transpose(sortn(transpose(F1:N2),3,,1,false,2,true)),"select Col1,Col2,Col3 limit 1 offset 1")
In A1. This is a self-expanding formula so does not need to be filled across and does not need helper rows.
EDIT
'Limit 1' may be omitted in the above formula as mentioned in the comment.
Also this is a little shorter:
=transpose(query(sortn(transpose(F1:N2),3,,1,false,2,true),"Select Col2"))
Formula in A1 = INDEX($F$2:$N$2,MATCH(COLUMN(A1),$F$3:$N$3,0)) and is dragged till C1
Formula in F3 = RANK(F1,$F$1:$N$1)+COUNTIF($F$1:F1,F1)-1 and is dragged till N3

EXCEL counting empty rows

A B C D E F G H
1 Y Y Y X
2 X X
3 Y Y
4 X X
5 Y Y Y X
Count the number of empty rows (from Columns A to E) and put result here. Answer should be 2 from example above.
Hi Folks,
I'm struggling to find the correct Excel formula to count the number of rows with no data from columns A through E, and putting that answer in a cell. These 'empty rows' may have data in later columns (like F, G, H), but I just want to count the rows with no data from columns A to E.
Any help would be appreciated.
Since array formulas tend to confuse people, here's a non-Array formula approach:
Place =IF(COUNTA(A1:E1)=0,1,0) into row 1 of (for example) column I and drag down to row 5. Then place a sum formula below that to get the answer, for example: =SUM(I1:I5)
Try this array formula,
=SUM(IF(ROW(1:5), IF(A1:A5&B1:B5&C1:C5&D1:D5&E1:E5="", 1)))
Remember to finalize with ctrl+shift+enter, not just enter.
You could also use a variation on the standard formula for getting row sums of a 2d array
=SUM(N(MMULT(N(A1:E5=""),TRANSPOSE(COLUMN(A1:E5)^0))=COLUMNS(A1:E5)))
or
=SUM(N(MMULT(N(A1:E5="Y"),TRANSPOSE(COLUMN(A1:E5)^0))=0))
Again they are array formulas and have to be entered with CtrlShiftEnter

Is there a formula that inputs on nth row of column A by reading what's in column F and/or D on their congruent rows?

I'm very new to excel programming. Currently I'm working on an excel worksheet and I need a formula that inputs on nth row of column A by reading what's in column F and/or D on their congruent rows. So far I have something like:
=IF(AND(D:ROW(n)=0,F:ROW(n)="x"),A:ROW(n)="e",IF(D:ROW(n)=0,"N","X"))
e.g.
A B C D E F
1 e 0 x
2 N 0
3 X 2
Put this in A1:
=IF(D1 = 0,IF(F1="x","e","N"),"X")
And copy down.
The references are Relative, so as the formula is copy/dragged down they will change on their own.

Resources