I need to find the most frequent word (categorical text, e.g."T2") in a row, but not across all columns. If the range was continous I would attempt something like:
=INDEX(B3;M3,MODE(MATCH(B3;M3,B3;M3,0)))
However, I'm doing this for multiple variables and don't want to make a separate subset sheet/file for each one so hope this is possible. I'm attempting to use the following formula but get an error message that hightlights the MODE function:
=INDEX((B3;F3;J3),MODE(MATCH(B3;F3;J3,B3;F3;J3,0)))
My data looks something like this:
person A person B person C
ID Var1 Var2 Var3 Var4 Var1 Var2 Var3 Var4 Var1 Var2 Var3 Var4
1 T2 C1 N f T2 C1 N f T4 C9 Y e
2 T4 C5 Y b T4 C1 Y b T2 C1 N e
3 T2 C2 N g T4 C5 Y d T2 C1 N f
4 T4 C9 Y e T4 C1 Y b T2 C1 N e
5 T1 C2 N b T2 C2 N h T2 C2 N g
6 T4 C9 Y b T4 C1 Y b T4 C9 Y f
7 V2 C1 Y c V6 C2 N c T2 C2 N h
Example
And the result I want is to add a column to the end that gives me the most common value/name, exapmle for Var1:
ID Mode_Var1
1 T2
2 T4
3 T2
4 T4
5 T2
6 T4
7 NA
Am I on the right track? Is this possible using Index, Mode and Match? Is there another way if this doesn't work? Thanks for any help!
EDIT: Added table (same as in image), made range in first example correspond to example data
You would use a countif in an array form of INDEX/MATCH:
=INDEX(B2:M2,MATCH(MAX(IF(MOD(COLUMN(B2:M2),4)=2,COUNTIF(B2:M2,B2:M2))),IF(MOD(COLUMN(B2:M2),4)=2,COUNTIF(B2:M2,B2:M2)),0))
Being an array formula it needs to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode. If done correctly Excel will put {} around the formula.
Put this formula in N2, press Ctrl-Shift-Enter, then copy/drag down.
Given a setup as shown, use this array formula* in cell B13 and copy over and down:
=INDEX(INDEX($B$3:$M$9,MATCH($A13,$A$3:$A$9,),0),MODE(IFERROR(MATCH(INDEX($B$3:$M$9,MATCH($A13,$A$3:$A$9,),0),IF($B$2:$M$2=B$12,INDEX($B$3:$M$9,MATCH($A13,$A$3:$A$9,),0)),0),-COLUMN($B$3:$M$9))))
The #N/A results mean that there was no most frequent entry for that ID and Var (all three had different entries). If you want to put something else there,wrap the formula in an IFERROR.
*Array formulas must be confirmed with Ctrl+Shift+Enter instead of just Enter. When done correctly, the formula will be surrounded by curly braces {=formula}, those are added automatically so don't try to add them manually.
Related
I have 4 equations, with 4 unknowns, a,b,c,e
w = c + 0.43*a
x + gb = pc + 2*e
y + 2a + hb = qc + 20.43a + e
z + bi = cr
What would be the best way to solve this in Excel?
I searched and found that LINEST might be a good function to use, but couldn't get it to work
Thanks
First rewrite all you formulas in the form
Ai*(a)+Bi*(b)+Ci*(c)+Ei*(e)=Ki
Then for each equation fill out a row in the matrix
A1 B1 C1 E1 a K1
A2 B2 C2 E2 x b = K2
A3 B3 C3 E3 c K3
A4 B4 C4 E4 e K4
Then use MInverse and MMultiply functions to solve for a,b,c and e
A,B,C,E are the constants multiplying each variable. Set them to 0 when they are not in the formula, and make sure you carry the negative sign.
i is just a way to represent the equation number.
K is the constant in the equation with out a variable attached to it.
So provided I did the formula rearrangement properly, one possible result would be:
Cant take it farther than this as numbers would be needed for g, p, h, q, i, and r (not to mention w, x, y, and z). Though you could set those up in cells so you sheet would automatically update when you entered values.
I have a Table like this in Sheet1
A B
1234.jpg | c1
1234.jpg | c2
1234.jpg | c3
3456.jpg | c8
3456.jpg | c9
3456.jpg | c10
haha.jpg | c2
haha.jpg | c5
haha.jpg | c9
I need the to match the data according to the Columns in Sheet2 and the data should result something like this.
c1 c2 c3 c4 c5
123.jpg Y Y Y N N
3456.jpg N N N N N
haha.jpg N Y N N Y
I am currently only able to make out this
=IF(ISERROR(MATCH(A2,Sheet1!$A$1:$B$9,0)),"Y","N")
Which returns Y as long as A2 matches something from the array. How do I go about matching it as the Column in Sheet2? I'm open to using functions or VBA
Use following formula to D3 cell as per screenshot.
=IF(SUMPRODUCT(($A$2:$A$10=$C3)*($B$2:$B$10=D$2))=1,"Y","N")
....................................................................................................................................................... You can also use this array formula.
=IF(ISNUMBER(MATCH($C3&D$2,$A$2:$A$10&$B$2:$B$10,0)),"Y","N")
Press CTRL+SHIFT+ENTER to evaluate the formula as it is an array formula.
After entering formula as array formula, drag and drop to right and down as you need.
I'm a novice in excel. I'm using Excel 2010. My spreadsheet looks something like this:
0 A B C D
1 X 10€ X: (sum of all incomes, made by A)
2 Y 20€ Y: (sum of all incomes, made by B)
3 Z 5€ Z: (sum of all incomes, made by C)
4 X 4€
5 Z 6€
I have a list of incomes and outcomes, collected/paid for by 3 different persons. I'd like to format the first column: if the content of the cell is 'X', the income in that row is added to X's sum of all incomes, if it's Y, add to Y's sum, same for Z.
Something like this (for A1):
"if content = X, add B1 to D1; if content = Y, add B1 to D2; if content = Z, add B1 to D3"
How do I write the formula?
Use the =SUMIF() formula.
Before you start, remove the colons from C1, C2 and C3.
In D1 write this formula:
=SUMIF($A$1:$A$5,C1,$B$1:$B$5)
... and copy or drag the formula down to D2 and D3.
Remember the $-signs in the formula to lock the ranges when copying or dragging.
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
I have altered a statement I got from a previous answer a bit and it now looks like this:
=IF(C6=$R$3,IF(D6<=0.99,$U$2,IF(AND(D6>0.99,D6<=4.99),$U$3,IF(AND(D6>4.99,D6<=14.99),$U$4,IF(AND(D6>14.99,D3<=29.99),$U$5,IF(AND(D6>29.99,D6<99.99),$U$6,""))))),$S$8)
It all works fine until you change the value in cell D6 to say £45 when it still picks up the figure in cell U5.
Can you or anyone else help me tweak this so that it works? I need a statement to do the following:
If C2=R2 and D2 is < T2 then U2, if D2 is >T but T3 but < T4 then U4 if D2 is > T4 but < T5 then U5, if D2 is > T5 but < T6 then U6 BUT if C2 does not equal R2 then S8
Take all your problems and rip them apart:
If C2=R2 and D2 is < T2 then U2, if D2 is >T but T3 but < T4 then U4 if D2 is > T4 but < T5 then U5, if D2 is > T5 but < T6 then U6 BUT if C2 does not equal R2 then S8
Start with this using NA() to represent parts which haven't been completed yet (this will show the #N/A value in the cell):
=IF(C2=R2,NA(),S8)
Add the lookup based on D2:
=IF(C2=R2,IF(D2<T2,U2,NA()),S8)
Assuming that the next part is D2 > T2 and D2 < T3 (althought strictly this formula says D2 >= T2) and result is U3:
=IF(C2=R2,IF(D2<T2,U2,IF(D2<T3,U3,NA())),S8)
Now add between T3 and T4:
=IF(C2=R2,IF(D2<T2,U2,IF(D2<T3,U3,IF(D2<T4,U4,NA()))),S8)
Between T4 and T5:
=IF(C2=R2,IF(D2<T2,U2,IF(D2<T3,U3,IF(D2<T4,U4,IF(D2<T5,U5,NA())))),S8)
Finally between T5 and T6:
=IF(C2=R2,IF(D2<T2,U2,IF(D2<T3,U3,IF(D2<T4,U4,IF(D2<T5,U5,IF(D2<T6,U6,NA()))))),S8)
We still have NA() because you haven't defined the behaviour for C2=R2 and D2 >= T6
As Stobor said in the comment to your original question, using VLOOKUP would be much better - see http://office.microsoft.com/en-us/excel/HP052093351033.aspx for details
Your current structure in the T and U columns won't work with VLOOKUP because:
the next largest value that is less
than lookup value is returned
This would mean that VLOOKUP would return U3 when you wanted U2, U4 instead of U3 and so on. To solve this you would need to move all of the entries in the U column down by one row, put a dummy value or =NA() into U2 and create a value in T7 that was greater than the existing value in T6