How to get weighted sum depending on multipliers in column in Excel? - excel

I have the table in Excel:
In column C (Sum) I want to get sum this way:
If in column A or B value is 1 then take Amount 48 and multiply by Multiplier (1) = 2.
If in column A or B value is 0 then take Amount 48 and multiply by Multiplier (0) = 1,5.
Then K1 and K2 summed.
So for row 2 the result in column C will be: 48*2 + 48*2 = 192.
For row 5 the result in column C will be: 48*1,5 + 48*2 = 168.
Is it possible to automate this process using Excel formula for C column (inspite of number of columns)?

Or you could use Countif (no shorter though)
=COUNTIF(A2:D2,0)*I$2*I$1+COUNTIF(A2:D2,1)*I$3*I$1

Use Ctrl+Alt+Enter when entering (since it's an array formula)
EDIT: I'm not great with formulas, so there is I'm sure a shorter alernative...

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))))

Formula to Return Text in the Row of Largest Number

Column A Has Text & Columns B, C & D contain numbers.
For Ex.)
A... …B C D
John 4 6 2
Dave 4 6 4
Mike 4 5 1
Bill 2 5 9
I would like a cell to return the name in column A that has the Largest Number in Column B. And if there are similar numbers, go to the next column and determine which is highest, and if that is tied go to the next column and so on.
Any help would be appreciated.
We can de-conflict ties.In E1 enter:
=B1 + C1/(10*MAX(C:C))+D1/(100*MAX(D:D))
and copy down. Then in another cell enter:
=INDEX(A:A,MATCH(MAX(E:E),E:E,0))
EDIT#1
This is only good for 3 columns of numbers, but it is very easy to add additional de-confliction terms if necessary:
=B1 + C1/(10*MAX(C:C))+D1/(100*MAX(D:D))+E1/(1000*MAX(E:E))
For an expandable number of rows/columns, use a helper row with the same number of columns as number columns in your data. The formulas below reference the following image (the data are in A1:G7):
B9-->=MAX(B1:B7)
C9 (fill over the remaining columns to G9)-->
=MAX(IF(MMULT(--($B1:B7=$B9:B9),--(ROW(INDIRECT("1:"&COLUMNS($B9:B9)))>0))=COLUMNS($B9:B9),C1:C7))
The following formula will give the answer (shown in A9 above):
=INDEX(A1:A7,MATCH(TRUE,(MMULT(--($B1:G7=$B9:G9),--(ROW(INDIRECT("1:"&COLUMNS($B9:G9)))>0))=COLUMNS($B9:G9)),0))
UPDATE WITH ALTERNATIVE METHOD
Using a helper column instead, again referencing the image below (the data are in A1:G7):
I1 (fill down to I7)-->
=SUM(--(MMULT(SIGN(B1:G1-$B$1:$G$7)*2^(COLUMN(G1)-COLUMN(A1:F1)),--(ROW(INDIRECT("1:"&COLUMNS(B1:G1)))>0))>0))
The following formula will give the answer (shown in J1 above):
=INDEX(A1:A7,MATCH(MAX(I1:I7),I1:I7,))
As a bonus, notice that the helper column corresponds to the order that you would get from sorting the data by each column left-to-right. In other words, you could use the helper column to perform a formula-based multi-column sort on strictly numeric data. For the last image, entering the following array formula into a range with the same dimensions as A1:G7 gives a descending sort on columns B through G:
=IF(A1:A7=A1:A7,INDEX(A1:G7,MATCH(ROW(A7)-ROW(A1:A7),I1:I7,0),))

Formula for deviation from mean agreement

I have a dataset in Excel and I want to compute a formula for deviation from mean agreement.
Suppose the dataset is like this:
A B C D E
4 2 6 9
1 3 2
7 2 1
8 4 3
5 1 2
What I want to calculate has formula as (summation from i=1 to 5 (i.e., from A to E) |R-R'|/t)/N where N = 4 for 1st row, N = 3 for 2nd row and so on that is, no. of non null values for that row. R is current value in the row and R' is mean of the column for which we are considering R and t is no. of non null values in that vertical or column.
You will need to use the ABS() function to get the absolute value of the subtractions. To get the number of non-null cells you can use the COUNT() function. To only include items in a row that are not null you can use an IF() statement.
For example, if you data was in the range A1:E5 then the following formula would get the result for the first row if I've understood the calculation you are doing correctly:
=(IF(LEN(A1)>0,(ABS(A1-SUM(A$1:A$5))/COUNT(A$1:A$5)))+IF(LEN(B1)>0,(ABS(B1-SUM(B$1:B$5))/COUNT(B$1:B$5)))+IF(LEN(C1)>0,(ABS(C1-SUM(C$1:C$5))/COUNT(C$1:C$5)))+IF(LEN(D1)>0,(ABS(D1-SUM(D$1:D$5))/COUNT(D$1:D$5)))+IF(LEN(E1)>0,(ABS(E1-SUM(E$1:E$5))/COUNT(E$1:E$5))))/COUNT($A1:$E1)
Which results in 2.4853 for row 1

How to select certain rows in Excel that meet logical criteria of A & B

I have an excel sheet in CSV that has 8 columns A-H and thousands of rows with values 0 or 1 depending on truth value.
I'm looking for the Excel function in which I can select rows where column A and B are true so that I can check another columns probability given A&B. IE P((A&B)|D) (where | means given).
I'm really new to excel and having difficulties finding how to only select rows that meet this criteria.
The following formula entered in I1 will return a 1 if both A1 and B1 are true.
=IF(AND($A1=1,$B1=1),1,0)
Copy it down or autofill to identify all rows where A and B are true.
The $ sign before A and B make the column references absolute meaning if you drag the formula to the right, the references to columns A and B will remain.
Because Excel implicitly interprets 0 = FALSE and 1 (or any other number) = TRUE the formula could be shortened to:
=IF(AND($A1,$B1),1,0)
The probability of C being 1 given that A and B are 1 can be calculated by counting all rows where A, B and C are all 1 and dividing by the number of rows where both A and B are 1:
=COUNTIFS($A:$A,"1",$B:$B,"1",C:C,"1")/COUNTIFS($A:$A,"1",$B:$B,"1")
Again, references to A and B are absolute, while C is relative so you can drag right to get probabilities for columns D to H.
COUNTIFS only counts the rows where all of the criteria are met and allows you to specify up to 127 range/criteria pairs.
EDIT
You could also use:
=AVERAGEIFS(C:C,$A:$A,1,$B:$B,1)
to get the probability.

How to do a little math in the criteria_range of Countifs Functions (using OR in Countif)

The Excel File is like this
A B
1 0
0 1
1 1
0 1
0 0
1 0
I want to use Countifs function to count how many rows have at least one "1" in any columns, like
=Countifs(A:A+B:B,">=1")
or
=Countifs(or(A:A=1,B:B=1))
I know I can add a Column C, let Column C = Column A + B, and then just count Column C; or I can count the total rows and count rows with "0" in both columns, and then calculate Total Row - Both "0". But in real Scenario, I have more complicated situation, so I prefer not using these two solutions.
Use a SUMPRODUCT function to provide cyclic calculation.
=SUMPRODUCT(--((A1:A6)+(B1:B6)>=1))
SUMPRODUCT does not like trying to calculate text values and full column references slow it down so keep your ranges to a minimum. Using the INDEX function can help isolate a dynamic range of true numbers.
Another solution using array formula:
=SUM(IF(A1:A6=1,1,IF(B1:B6=1,1,0)))
Being an array formula, you'll have to enter this formula by pressing Ctrl+Shift+Enter together.
Use =COUNT(A:A)-COUNTIFS(A:A,0,B:B,0) to count both 0 columns and subtract it from the total rows:
Or you can use:
=COUNTIFS(A:A,1,B:B,1)+COUNTIFS(A:A,0,B:B,1)+COUNTIFS(A:A,1,B:B,0)
if it is not clear what it the total number of rows.

Resources