Calculate standard deviation of same text values between cells in same column - excel

The last few days I have been trying to create a macro in Excel which can calculate standard deviation which will take values from column B of same text values between different cells in column A and give the result in corresponding cell in column C. In my sheet there are lots of different text values in column A and corresponding value in column B. I want to take all values of column B from first row to last row of corresponding same text in column A and calculate the standard deviation of these values and shows the result in column C.
As an example, when it starts from first cell (aass) then it has to count all aass and take values from corresponding cell of column B after that calculate standard deviation. Please help me out.I will be happy to hear from you guys. I am trying to show how my sheet which will look like as below:
column A column B column C
text value result(standard deviation)
aass 112 35.16
aadd 243 12.9
ffdd 523 108.55
aass 198 35.16
aadd 252 12.9
aass 136 35.16
ffdd 342 108.55
ffdd 312 108.55
aadd 222 12.9
aadd 255 12.9
ffdd 322 108.55
aass 112 35.16
jjhgf 487 25.8
pouwe 565 6
jjhgf 451 25.8
jjhgf 424 25.8
qwert 643 0
pouwe 553 5
qwert 643 0
..... .... ...
..... .... ...

This is what I used without VBA. This is an array formula (entered using Ctrl+Shift+Enter) which resides in cell C1:
=STDEV(IF($A$1:$A$9=A1,$B$1:$B$9))
(In in my example file I have only 9 rows of data.)
In newer versions of Excel you can use this:
=STDEV.S(IF($A$1:$A$9=A1,$B$1:$B$9))
For the entire population use this:
=STDEVP(IF($A$1:$A$9=A1,$B$1:$B$9))
or
=STDEV.P(IF($A$1:$A$9=A1,$B$1:$B$9))
The following versions will be MUCH SLOWER:
=STDEV(IF(A:A=A1,B:B)) , =STDEV.S(IF(A:A=A1,B:B)) ,
=STDEVP(IF(A:A=A1,B:B)) , =STDEV.P(IF(A:A=A1,B:B)).

I will show you what I mean by a Table with structured references.
I copied your data for the text and value columns. I also added the header: Result to cell C1.
I then selected the Table option from the Insert ribbon (on the Tables tab)
I then entered this formula in C2 as an array formula, confirming it by holding down ctrl+shift while hitting Enter
=STDEVP(IF(Table1[[#This Row],[text]]=[text],[value],""))
Excel automagically copied that formula down to the last row and produced the requested results. If you now add a row, the table will extend (including the formula). You can also add columns with different formulas.
In the formula above, Table1[[#This Row],[text]] refers to the context of the text column only on the row containing the formula, and [text] by itself refers to the entire text column; [value] refers to the entire value column.
The autoextension, and the ability to use the actual column labels is a desireable feature of Excel tables and structured references. It is similar to having dynamic named ranges, but easier to implement.

Related

How to populate a particular cell value between two columns in Excel?

I am facing problem to populate a cell value.
For example i have two columns A and B as shown below
A B
381 369
382 370.3
384 370.3
385 371
386 372
My aim is to get the respective value of column B value 370.3 as 382.
I tried using Vlookup formula "=VLOOKUP(D3,A:B,2,TRUE)"
Please help me to find the correct code to get the solution as in the image
If you wish to find "370.3" ie the contents of cell D3 then you will need to match in column B and index in column A so:
=INDEX(A1:A6,MATCH(D3,B1:B6,0))
VLOOKUP will not work as it indexes the leftmost column... or you change the data order.

Excel splitting one row into separate rows of a fixed number of colums

Here is a sample of the data I have in one row in an excel file. I would like to split it into multiple rows after every seven columns
15-Feb 20 783 175 105 $180 $973 15-Mar 31 900 58 145 $106 $140
to
15-Feb 20 783 175 105 $180 $973
15-Mar 31 900 58 145 $106 $140
You can use this formula:
=INDEX($1:$1,INT(COLUMN()+(ROWS(A$5:A5)-1)*7))
drag/copy this formula across till row 7 and down as required.
Issue with this formula is it will return 0 if cell is blank.
So alternatively, you can check for cell blank condition and write formula as:
=IF(ISBLANK(INDEX($1:$1,INT(COLUMN()+(ROWS(A$5:A5)-1)*7))),"",INDEX($1:$1,INT(COLUMN()+(ROWS(A$5:A5)-1)*7)))
If you have a well defined and deterministic way to split the two halves (for instance, columns "A" to "D" is the first half, while columns "E" to "H" is the second), you can enter a formula in a different sheet like (this is pseudo-code; you will need to verify the syntax):
Cell "A1" of the new sheet: ='Other_Sheet'!A(round(row()/2)+1)
Cell "A2" of the new sheet: ='Other_Sheet'!E(round(row()/2)+1)
The indirect reference is made such that it will go to the next row in the source sheet every two rows in the new sheet.

Equation/ sorting to separate one long column of data into separate columns

I have two columns of data in an excel spreadsheet that is listed like, each date has three numbers associated with it. It is shown like this:
1 112
1 123
1 456
2 788
2 989
2 901
What I am trying to do is have the data shown like this:
1
112
123
456
Then in another column next to it have;
2
788
989
901
Okay, this can be done pretty easily/quickly.
First, select your entire column that has # ### and go to Data --> Text to Columns, and choose “Delimited”, then use a “Space” delimiter. This will separate your numbers by the space, so 1 and 2 will be in Column A, and the three digit numbers are in B (or wherever you decide to put them).
Then, just get the unique values from column A. I tend to copy the entire column to a temporary column (or worksheet), then highlight them and go to Data --> Remove Duplicates. Now you have a list of unique numbers. Copy and paste these (transposing) into (for example) column D.
Then, in D2, enter this formula (adjust ranges as necessary) as an array, using CTRL+SHIFT+ENTER:
=IFERROR(INDEX($B$1:$B$6,SMALL(IF($A$1:$A$6=D$1,ROW($B$1:$B$6)-ROW($B$1)+1),ROWS($B$2:$B2))),"")
Here’s a screenshot of the final output:

Excel VLOOKUP or INDEX MATCH

Lets say I have 3 columns of data
AMOUNT(A) AMOUNT(B) INVOICE(C)
55 49 4541
47 47 1515
42 47 4478
86 12 9993
12 100 1224
5 44 1452
100 4287
99 4444
What I need to check to see if the value in column A matches a value in column B. If there is a match, it will return the value from column C in column D. Now this is easy with a VLOOKUP however I am dealing with 700+ lines and there are multiple amounts that match. INDEX(MATCH) could work but it only returns one value. Is this a VB only problem?
I.E Value 47 exists in column B twice so therefore column D would return both invoice numbers (1515 - 4478)
In VBA, the problem would be trivial as you have already correctly described the logic with the problem statement itself.
Using Excel functionality only, without VBA is the interesting problem. You need to do the following steps to achieve an output that looks like this...
The steps are as follows:
Pivot Table: Make a pivot-table from the Columns (B) and (C) with Rows Fields as (B) and (C) and the minimum of AMOUNT(B) as the Value field. (See Figure below)
Helper Columns: Make a column on the side of the pivot table, say (Q) which is simply equal to everything in column (P)
Contd ... : In column (R) (which unfortunately happens to be in the sheet's column Q, sorry for the confusion there), as shown, for cell Q20 for e.g. put in the formula
=IF(P21=P20,Q21&","&M20,M20)
That will result in the creation of something like the table below:
Table:
(P) (Q)
12 9993
44 1452
47 4478,1515
47 4478
49 4541
99 4444
100 4287,1224
100 4287
Now the hard work is done. All you need to do is to lookup using VLOOKUP key-value pairs from this helper table (P)(Q)
- It will be very fast because the pivot table always keeps it sorted and hence an exact LOOKUP is not necessary.
- Screenshots are shown below for the Pivot table as well as for the final VLOOKUP formula
Pivot Table and Helper Table:
Final Formula:
so I'm using the Countif to see if there are dups based on column A.
In the D column type, =IF(COUNTIF($A$2:$A$9,B2)>0,C2,"")

Excel multi-column averages

I need to take the value in two data columns A and C, get a percentage by dividing the current value of columns A and C by the top value (which is a total), and then average the two percentages and spit them out in column D. For example D2 should be (100(226/508)+(100(218/490))) / 2). I'd prefer to do this with one equation - is it possible?
A B C D
1 508 490
2 226 44.49% 218
3 229 45.08% 221
The formula you want is
=(100*A2/A$1 + 100 *C2/C$1)/2
and the select all of column D downwards and then edit->fill down
The relative reference A2 will change in each row to the new row but A$1 is an absolute reference and will stay as the value in row 1.
You can also do this with array formula that do the fill down for you. See MS article

Resources