Custom SUMPRODUCT() - excel

I have the following table:
My objective is to spread out the 10,000 units across the 5 months, given the weightings below each month. The row adjacent the 10,000 is my best attempt at getting this (I have spent a few hours on this). The yellow is what I am after.
The logic I have tried to use to get the calculation is as follows: Calculate the even spread across the months (in this example 10,000 / 5 = 2,000 = X). Multiply each month weighting to get the weighted amount (in this example to get M2 = 1,600 and M4 = 3,000: X + (X * M2 weighting) etc). You can then take the total 10,000 minus the summation of these which will give you 5,400, which you can then distribute across the months don't don't have a weighting. There must be an easy way to do this with a SUMPRODUCT but I can't seem to figure it out.
My best attempt so far is this:
=IF(B3=0,SUMPRODUCT(ABS((10000/5)*$B3:$F3)),(10000/5)+((10000/5)*B3))

Try the following:
Formula in B3:
=IF(B$2=0,($A3-SUMPRODUCT(($B2:$F2<>0)*(($A3/5)*(1+$B2:$F2))))/COUNTIF($B2:$F2,0),($A3/5)*(1+B$2))
Drag right.
Logic:
=IF(B$2=0,<true>,<false>) - Check if cell above equals zero
If above is false (so other than 0) then: ($A3/5)*(1+B$2) - First divide (10000/5) and multiply that outcome by (1-<percentage>)
If IF yields true - Check which cells in range are other than zero and multiply by the same logic as per step 2. The sum gained with SUMPRODUCT can then be deducted from 10000 and devided by the count of cells that actually do hold zero (hence the COUNTIF).

Related

COUNTIF function to count specific, but non consecutive, cells in a row

I have an NFL spreadsheet where each row represents a specific team, and every 5 columns represents weekly information about the team (Column A is the team, Columns B-F are stats for week 1, G-K are stats for week 2, etc.). I am trying to perform different calculations on information from the same stat for each week (I.E. sum of columns B,G...). One column includes the teams margin of victory for each week. In order to calculate the teams Win/Loss record, I attempted to use a COUNTIF() function, counting each Margin of Victory column for each week - count a Win for each week where the MOV is greater than 0, Loss for less than zero.
=COUNTIF((Weeks!E3,Weeks!J3,Weeks!O3,Weeks!T3,Weeks!Y3,Weeks!AD3,Weeks!AI3,Weeks!AN3,Weeks!AS3,Weeks!AX3,Weeks!BC3,Weeks!BH3,Weeks!BM3,Weeks!BR3,Weeks!BW3,Weeks!CB3,Weeks!CG3),>0)
The result is a formula parse error, because I've entered too many arguments for the COUNTIF() function (although my assumption was adding parentheses around the data would make it one argument). The desired outcome, reference the picture for example, would be on another sheet to produce 1 loss and 1 tie (in separate cells) for Arizona (Week 1 margin = 0, week 2 margin = -6), and then replicate this over the course of 17 weeks as implemented in the formula.
Maybe some of these formula's:
For positive results:
=SUMPRODUCT((MOD(COLUMN(A3:CG3),5)=0)*(A3:CG3>0))
Or:
=SUM(INDEX((MOD(COLUMN(A3:CG3),5)=0)*(A3:CG3>0),))
For draws:
=SUMPRODUCT((MOD(COLUMN(A3:CG3),5)=0)*(A3:CG3=0))
Or:
=SUM(INDEX((MOD(COLUMN(A3:CG3),5)=0)*(A3:CG3=0),))
For negative results:
=SUMPRODUCT((MOD(COLUMN(A3:CG3),5)=0)*(A3:CG3<0))
Or:
=SUM(INDEX((MOD(COLUMN(A3:CG3),5)=0)*(A3:CG3<0),))
Change A3:CG3 to whichever range it actually goes to.
Instead of making a large countif, you can sum all of the individual countif functions.
=SUM(COUNTIF(Weeks!E3,">0"),COUNTIF(Weeks!J3,">0")...
So on and so forth. Since each countif function will return either a 0 or 1, summing all of those together should hopefully work. It might be a little annoying but this is how I've made formulas like that work. Let me know if this works for you.

Excel: Dynamic SUM with OFFSET calculation

I need to create a dynamic sum of data chunks out of a large data set contained in a csv file (>100k rows). The data is planned to be displayed in PowerBI but I have literately no idea of the DAX coding language or VBA. So I hope I can preformat the data in excel.
The way to distinguish the data sub-sets I want to sum up is a counting row. The rows starts with every new subset from 1 but the final number >= 1 is totally ‘random’.
The first row is the countingRow the second row is the dataRow.
> 1 45
2 20
3 20
4 10 -> SUM 95
> 1 30
2 5 -> SUM 35
> 1 X -> new SUM
I think it is possible to work with the SUM, IF and OFFSET function.
My plan was to check whether a cell contains a 1 or not. Check the range between two true values minus one cell, then calculate the offset sum in the other column.
But when I thought I found the solution I realized that I have no way to bring my pointer to a new data subset.
Which function do I need to move my calculation threw the column?
Is it even possible to do an calculation of this scale in excel?
PS: I'm although thankful for a DAX or VBA tutorial which could bring me to a solution.
In the following sample data image, use the following formula in D2.
=IF(OR(A3={1,""}), SUM(INDEX(B:B, AGGREGATE(14, 6, ROW($1:2)/(A$1:A2=1), 1)):INDEX(B:B, ROW())), TEXT(,))
Fill down.
A slightly shorter formula without array type formula:
=IF(OR(A3={1,""}),SUM($B$2:B2)-SUM($C$1:C1),"")

Random Numbers with assigned Probability in Excel

Following is what I am trying to do:
I have got a bunch of items, lets say from A to J, a total of 10 items. Now I want to generate a total of 20 draws and in each draw I need 3 items from the above 10 items. Now if the first item comes out as A, it should not show up in second and third item irrespective of its assigned probability.
Lets say:
A - 4%
B - 20%
C - 1%
D - 16%
E - 5%
F - 7%
G - 3%
H - 21%
I - 6%
J - 17%
Now, I need to randomly generate 3 items from the above list in each draw, according to their assigned probabilities, but lets say if first item is B, the second and third item should not be B. I should repeat the same process for 20 draws.
Answer Should Look something like this:
1st Item 2nd Item 3rd Item
1st Draw B D J
2nd Draw D E F
3rd Draw B H G
The numbers should be generated according to their assigned probabilities.
Thanks in advance.
For a formula route:
You will need to build two helper columns. The first is a running total
I put your values in G1:H10
Then in I1 I put 1
In I2 I put:
=I1+(H1*100)
And copied down:
I then created the second helper. In K1 I put:
=INDEX(G:G,MATCH(ROW(1:1),I:I))
And copied down 100 rows.
This created a dynamic range of the probability.
Then in B2 I put:
=INDEX($K:$K,AGGREGATE(15,6,ROW($1:$100)/(COUNTIF($A2:A2,$K$1:$K$100)=0),RANDBETWEEN(1,100-SUMPRODUCT(COUNTIF($A2:A2,$K$1:$K$100)))))
Copied over three and down as many as wanted:
Caveats:
This works only with whole percentages, no 20.513%.
Every choice in the table must be at least 1%.
The total percentage must equal 100%
Here is another way according to this website (https://www.mrexcel.com/forum/excel-questions/372071-random-numbers-assigned-probabilities.html) post #7. You can use cumulative value and do the similar test.
Add a helper column C and use this formula: =SUM($B$2:B2), and drag down.
On cell F2, you can enter this formula:
=INDEX($A$2:$A$11,COUNTIF($C$2:$C$11,"<="&RAND())+1)
It is basically counting the rows using RAND function and add 1 (the header row) to pick the item. Give it a try and let me know.
Here's something that combines the approaches in the two earlier answers. Like ian0411's answer it utilises the cumulative probability distribution. It also utilises Scott Craner's techique of constructing an array of 0's and 1's which indicate matches between the possible outcomes (A,...,J) and those which have already been drawn.
The formula in cellP2 is
=INDEX($A$2:$A$11,1+IFERROR(MATCH(RAND(),MMULT($D$2:$M$11,($B$2:$B$11)*(1-COUNTIF($O2:O2,$A$2:$A$11))/SUMPRODUCT($B$2:$B$11,(1-COUNTIF($O2:O2,$A$2:$A$11))))),0))
and this is copied into cells Q2 and R2 and then dragged down for each draw.
The probability distribution in $B$2:$B$11 has elements replaced by zeroes for any prior drawn items in the current draw (hat-tip to Scott for how this was achieved). The adjusted distribution is converted to a cumulative format via the kludgy matrix multiplication operation (couldn't think of a more elegant approach) and normalised to a "proper" cumulative distribution by dividing by the sum of its elements. Rather than using =1+COUNTIF(cumdist,"<="&RAND()) (where cumdist is the cumulative distribution) to pick out the element of cumdist matching to the random variable, I have used an alternative of =1+IFERROR(MATCH(RAND(),cumdist),0).

How to sum under certain conditions in Excel?

I have a formula in Excel that I'm trying to work out. The formula is meant to return a sum under certain conditions.
If the salary is less than the limit amount and is greater than 30 hours worked, it is meant to sum the cells. If false then it is meant to return a calculation, but this needs to return by minus itself from a sum total to get to a final result.
The below formula only returns the reduced rate not the sum total - reduced rate = final result:
=IF($G$7*52<$K$5*(AND($C$4>30)),SUM($K$7:$K$9),($G$7*52)-$K$5)*$K$6
I can't seem to manage to think how to return sum total is their a formula I can use that could involve this part of the formula:
($G$7*52)-$K$5)*$K$6
Something like this?
=IF($G$7*52<$K$5*(AND($C$4>30)),SUM($K$7:$K$9),SUM($K$7:$K$9)-(($G$7*52)-$K$5)*$K$6)

Calculate the average of the 3 highest grades

I'm relatively new to excel but I am making a gradebook that calculates all of my grades.
One of my classes has an interesting way to calculate grades. There are 4 quizzes, and the lowest one will be dropped (essentially removed from the calculation completely).
How would I go about this, I tried using
=((SUM(D2:D5)-SUM(SMALL(D2:D5,4)))/(COUNT(D2:D5)*100))
on data like this
D2|75
D3|80
D4|83
D5|65
So in this case, I want the 65 to be removed, then calculate the average
I am not getting any error but the average is wrong
Subtract 1 from the count. In the example you are dividing by 4 instead of 3.
Like this:
=((SUM(D2:D5)-MIN(D2:D5))/(COUNT(D2:D5) - 1) * 100
You can average the top 3 out of 4 with this formula
=AVERAGE(LARGE(D2:D5,{1,2,3}))
Add the four tests together, subtract out the min(.) of the same range, and divide the total by 3.
If your scores are in B2, C2, D2, and E2 then something like:
=(SUM(B2:E2)-MIN(B2:E2))/3
Was this helpful?

Resources