Excel: SUMPRODUCT with percentages - excel

I use the following formula to calculate the SUMPRODUCT of the values in a column with the condition that there is a match between B2:B6 and A1:A3 (shoutout to user:8162520).
=SUMPRODUCT(($B$1:$B$6=$A$9)*(G2:G6))
Now however I would like to subtract to that result the percentage in C1 and/or D1, and "give it" to one of the other blue numbers, again with the condition that there is a match between C2:C6 or D2:D6 and A7:A9.
So for example in G7 the result for "1" should be 50% of 10 + 75% of 5, because "2" takes 50% of 10(G2) and "3" takes 25% of 5(G5).
The point is to create an overview of how many hours employees (1,2,3) have to spend spend on project B2:B6 for each week (E,F,G), and what happens if other employees take a certain percentage of the workload (C,D). What is the most efficient way to do this?
The numbers in A, B,C, D are reference numbers, they should not be part of the calculation. Maybe it's clearer if I use letters. See also the right results for E7:G7. The outcome must be the sum of the values in each column (workload) minus the percentage in C and D IF there is someone sharing the workload:

So deducting the percentage in C1:D1, presumably where there is no workload the result should be zero?
=SUMPRODUCT(($B$2:$B$6=$A7)*($C$2:$D$6<>"")*(1-$C$1:$D$1)*G$2:G$6)

Related

How to calculate moving average 7 days of milk production of a each cow, Dates not sorted. Excel

The daily milk production of each cow is recorded daily. I would like to cancel out the noise. Therefore I would like to use a moving average of seven days ( 3 days before and 3 days after, including current date production) in Excel.
The data is not ordered according to date therefore offset function cannot be used.
Additional Information: "Date" is in Column A, Cow No in Column B and Milk in Column C . Rows are from 1-22.
The expected result would be get get a moving average of milk for 7 days of each cow ( -3 days before <=current date and < days+3 days after current date from each cow.
Similiar function used to calculate rolling average of past year is =AVERAGEIFS(B2:K2,B1:K1,">"&TODAY()-365,B1:K1,"<"&TODAY()). A similiar formula could be used.
Problem when using sumproduct formula: No Data for 7 days should be 0 7D Average. However is given 1.79 .Rolling AVerage with the Sumproduct formula Problem
You can try to use a combination of SUMPRODUCT and AVERAGE functions. Note that this is an array formula, so you need to enter it using Ctrl+Shift+Enter keys:
=SUMPRODUCT(AVERAGE(IF(($B$2:$B$22=B2)*($A$2:$A$22>=(A2-3))*($A$2:$A$22<=(A2+3)),$C$2:$C$22)))
Result:
The average for the first three entries (D2:D4) is exactly the same as the value in column C, as there are no other dates provided for the range between 23-29 January. The remaining values (D5:D22) should properly present the 7-day average values.
This may not be the pretiest solution but it works. We can use countifs in the following way:
1. Create a column that combines Cow no and Date (I called it CowNoDate) with the format CowNo + "-" + date(as number). I put it in column C.
2. Sort list by this new column
3. use the following formula in column E to calculate the running average:
=SUMIFS(D:D,C:C,">="&B2&"-"&(A2-3),C:C,"<="&B2&"-"&(A2+3))

How to create Count if and average formula together

For example:
count if cell d12,d16,d20,d24 are greater then zero
take that number and then divide it by
d12,d16,d20,d24 to get the average of those four cells, even if one or more cells have zero in them.
This has to be done to get weekly and monthly average headcount.
Maybe:
=(D12+D16+D20+D24)/(1*(D12>0)+1*(D16>0)+1*(D20>0)+1*(D24>0))

Median Selling Price Excel Table

I have a spreadsheet with different products, listing units and retail value sold like the example below
Product Units Value
A 10 100
B 15 80
C 30 560
I'd like to compare the Average Selling Price with the Median Selling price, so I am looking for a quick formula to accurately calculate the median.
The median function requires the entire series, so for Product A above I would need 10 instances of 10 etc. How can I calculate the Median quickly considering the condensed form of my data?
Without writing your own VBA function to do this there are a couple of approaches that can be taken.
The first expands the data from its compressed frequency count format to generate the full set of observations. This can be done manually or formulaically. On the assumption the latter is required, it can be achieved using a few columns.
All the blue cells are formulae.
Column Eis simply the cumulative of column B and F is an adjusted version of this. Column H is just the values 1 to 55, the total number of observations given by cell L2. Column I uses the MATCH() with its final argument as 1 to match each observation in H against the adjusted cumulative in F. Column J uses the INDEX() function to generate the value of the observation. (Observations 1-10 have value 100, 11-25 have value 80 and 26-55 have value 560 in this example). The MEDIAN() function is used in cell M2 with column J as its argument.
This approach can be refined to take account of varying numbers of products and data points through the use of the OFFSET function to control the range arguments of the MATCH(), INDEX() and MEDIAN functions. And, of course, adjacent cells in columns I and J could be combined using a single formula - I've shown them separately for ease of explanation.
The second approach involves sorting the data by value (so in this case the data rows would become Product B in row 2, product A in row 3 and product C left as-is in row 4). It is then a case of identifying the middle observation number (if the number of observations is odd) or the middle pair of observation numbers (if the number of observations is even) and then determining the value(s) corresponding to this/these middle observation(s). In this approach the adjusted cumulative in column F is still used but rather than explicitly calculating the values in column I and J for every observation it can now be restricted to just the middle observation(s).
I think there is no way around compromises. Either using big amounts of helper cells or having the table sorted by the values.
Helper cells:
Formula in F4:AS6:
=IF(COLUMN()<COLUMN($F$4)+$B4,$C4,"end")
Formula in D2:
=MEDIAN(F4:AS6)
Sorted:
Formula in F4 downwards:
=SUM($B$3:B3)+1
Formula in D2:
=SUM(LOOKUP(INT(SUM(B4:B6)/2+{0.5,1}),F4:F6,C4:C6))/2

If column A matches column C input column D into column B

I have a sales tracking sheet where column A contains the profit margin of a particular job (i.e.33%), Column C is the profit margin range(i.e. 31-40%), and Column D is the corresponding commission to that specific range identified in Column C (i.e. 31-40% = 3% commission).
What I want is a formula that will automatically pull the Commission from Column D into Column B when I enter the profit margin of that particular job in Column A.
Any ideas/does that make sense?
Assuming that the values in column A are formatted as percentage, you could use something like this:
=INDEX(D$1:D$10,MATCH(A1*100,1*LEFT(C$1:C$10,FIND("-",C$1:C$10)-1),1))
And press Ctrl+Shift+Enter after entering the formula instead of Enter alone.
This will return a value from range D$1:D$10 where the value from A1 (multiplied by 100 to remove the decimals) is less than the lower bound of the margin range in range C$1:C$10.
Change the ranges accordingly.
In B1, put:
=IF(A1=C1,D1,0)
You can obviously change row numbers to work as needed.
The IF statement has 3 parts, the condition:
=IF(A1=C1,
Here I'm testing to see if the expression is TRUE or FALSE. I can do anything I want here, as long as it evaluates to either a True or False condition.
Next, we specify the "True" result, and the "false" result, which are, respectively, what happens when those conditions are met. For the TRUE condition, we just want to use the value in cell D:
D1,
For the FALSE condition, I don't know what you want, so I just put in a 0.
0)
Note that all 3 parts of the IF statement are separated by commas - play around, you can do a LOT of different things!
EDIT: Just noticed that column C is a range, while A is a singular value. You're going to need to do something like #Jerry did with parsing out the range string.
I am assuming that columns A and B will be indefinitely long just based on how much data is collected, whereas columns C and D are just a reference table with 10 rows each for the 10 ranges (0 - 10%, 11 - 20%, 21 - 30%, etc.). Is this correct?
As an alternative to storing the profit margin range and corresponding commission in columns C and D as you now do, you could incorporate them directly into an IF statement that you use in column B. For example if 91-100% corresponds to 8% commission, 81-90% is 7% commission and so on, then you could insert this formula:
=IF(A2>90,0.08,IF(A2>80,0.07,IF(A2>70,0.06,IF(A2>60,0.05, ...
The advantage to this compared to using and index-match combination which references numbers extracted from the text ("11-20%"), is that you don't run the risk of losing data when the text ranges are altered in some way. (I.e. userproof.)

Taking the average of bottom n percent in Excel

I have a column of data in excel that I need to take the average of the bottom 10% of. My data reads:
1
2
3
4
5
6
7
8
9
10
so the average of the bottom 30% would be - (1+2+3)/3 = 2. Is there a way to automate this in excel where all I have to do is give it what percent I want and it gives me the answer?
A simpler version: no Array Formula or Indirect required
Assuming data in column A, and required percentage in cell B1 (as a decimal)
=AVERAGEIF(A:A,"<="&SMALL(A:A,COUNT(A:A)*B1))
I'm not entirely sure what you're looking for when you say 'where all I have to do is give it what percent I want and it gives me the answer', but you could perhaps try AVERAGEIF:
=AVERAGEIF(A1:A10,"<="&COUNTA(A1:A10)*0.3)
Assuming that the data is in the range A1:A10. You can have a reference for the 0.3 for the percentage.
=AVERAGEIF(A1:A10,"<="&COUNTA(A1:A10)*B1)
If you put the percentage in B1, then the formula will change accordingly.
Assuming your data is in A1:A10, and your desired % is in B1:
=AVERAGE(SMALL(A1:A10,ROW(INDIRECT("1:"&(B1*COUNT(A1:A10))))))
Note! This is an Array Formula! That means that you have to enter into the formula bar at the top (not in the cell), and press ctrl shift enter when you're done.
This will wrap the formula in these { }, so you'll know you did it right. Typing them in does not work, you have to ctrl+alt+enter!
How does it work?
ROW(INDIRECT("1:"&(B1*COUNT(A1:A10))))
The Count checks how many items you have in your list, so it knows how many numbers it will need to average. Let's say B1 is 40%.
40% of 10 items is 4, but 40% of 20 is 8.
Since it's 10 entries long, we'll creating an "array", a series of numbers from 1 to 4 (40%).
*SMALL(A1:A10*
SMALL finds the *n*th smallest number in a range. With our array of 1 to 4, it will find the lowest 4 entries.
AVERAGE(
Then we average the result :)

Resources