Multiple Complex IF conditions using 3 Tables - excel

If negative value is found in Total row (A2) in Table 1
Then look for fruit with the highest qty in that month in Table 2
Add the fruit qty to Table 1, a month prior so that the Total is equal to or greater than 0 at an incremental qty found in Table 3.
Please note that Total is sum of all fruit qty + previous month's qty - demand (not shown), it's cumulative.
So basically, we have -5 in March in Table 1.
Apple is the highest in March in Table 2.
So add 8 (2 boxes of Apple) to C4 (a month prior to March) in Table 1
I'm not sure if this is even possible using just a formula, maybe VBA is needed?
If this can be done using a formula would go into B3:G5

Put this in B3,
=IF(AND(C$2<0,MAX(C$8:C$10)=C$10),IF(MAX(C$8:C$10)=C$8,(INT((0-C$2)/$B$13)+1)*$B$13,IF(MAX(C$8:C$10)=C$9,(INT((0-C$2)/$B$14)+1)*$B$14,IF(MAX(C$8:C$10)=C$10,(INT((0-C$2)/$B$15)+1)*$B$15,C$2))),"")
and drag to G3. then put this in B4,
=IF(AND(C$2<0,MAX(C$8:C$10)=C$8),IF(MAX(C$8:C$10)=C$8,(INT((0-C$2)/$B$13)+1)*$B$13,IF(MAX(C$8:C$10)=C$9,(INT((0-C$2)/$B$14)+1)*$B$14,IF(MAX(C$8:C$10)=C$10,(INT((0-C$2)/$B$15)+1)*$B$15,C$2))),"")
and drag to G4. then put this in B5,
=IF(AND(C$2<0,MAX(C$8:C$10)=C$9),IF(MAX(C$8:C$10)=C$8,(INT((0-C$2)/$B$13)+1)*$B$13,IF(MAX(C$8:C$10)=C$9,(INT((0-C$2)/$B$14)+1)*$B$14,IF(MAX(C$8:C$10)=C$10,(INT((0-C$2)/$B$15)+1)*$B$15,C$2))),"")
and drag to G5.
Idea : convert input to positive value, find max, amount to order = ( (Positive input/incrementalQty)+1 ) * incrementalQty
Have a check.

Related

Populating Dates and Numeric Values from one table into another table

Below is a simple list from a much longer list of what I'm trying to accomplish.
Suppose I have a supply forecast with 10 dates and Quantities from And I have a list of projects in column A1 to C10
Date . Qty
5/7/2018 80
6/3/2018 100
7/9/2018 100
.....
Project . Qty Required . Qty Left
1 10 50
2 20 30
3 50 -20
4 20 -40
5 . 50 -90
....
I would like to populate two extra columns : Supply Date, Supply Qty Added. So my table would ideally look like this.
Project . Qty Required . Qty Left Supply Date . Supply Qty Added
1 10 50
2 20 30
3 50 60 5/7/2018 80
4 20 40
5 50 90 6/3/2018 100
If there were, lets say, more than 100 projects and a lot more supply dates, doing this exercise would be a little bit too manual.
I have formula for the first date and Qty(If Qty Required for Project row x is < Qty Left in Project row x-1), then bring over the Supply Date and Supply Qty Added.
but my trouble is adding the extra formula where if If Qty Required for Project row x is > Qty Left in Project row x-1, then don't do anything (or put in ''). BUT if the formula (If Qty Required for Project row x is < Qty Left in Project row x-1) is true, then use the 2nd supply date 6/3/2018.
I want my logic similar to Python where you initiate a variable (e.g. row = 0) , and then +1 once the first occurrence occurs so that it knows the grab the next row of values.
Is there a way to perform this in googlesheets, or do I have to leverage Appscripts for this type of exercise?
This can be done without a script.
One way to do this is to count the current number of non blank cells above the current row to decide which date and Qty to choose. The full formula looks something like this:
=IF($B2>$C1,INDIRECT("Sheet1!A"&COUNTA(INDIRECT("D2:D"&MAX(2,ROW()-1)))-COUNTBLANK(INDIRECT("D2:D"&MAX(2,ROW()-1)))+1),"")
Broken down into steps:
If($B2>$C1 checks if Qty required for project row x is > Qty left in project row x-1.
INDIRECT("Sheet1!A"... this is indirectly referencing the sheet that contains the dates and quantities that we want to pull. We know it comes from column A, we just have to decide which row is the "current" row to pull from
COUNTA(INDIRECT("D2:D"&MAX(2,ROW()-1)))-COUNTBLANK(INDIRECT("D2:D"&MAX(2,ROW()-1)))+1) Count the number of blank cells above the current row. Using this method to account for cells with formulas.
MAX(2,ROW()-1) since we start the formula on row 2, we only want to check back for blank cells as far as row 2.
Check out this test sheet.

ADVANCED EXCEL HELP: Divide when multiple conditions are satisfied.

Hi I am currently working on a large data spreadsheet and want to divide only when all conditions are satisfied. Below is the sample data
Article UOM Quantity
1002121 CAS 500
1002121 EA 1
1002121 INN 10
1002121 LAY 2,000
1002121 PAL 10,000
1002127 CAS 500
1002127 CS1 250
1002127 CS2 10
1002127 EA 1
1002127 INN 10
1002127 LAY 3,000
1002127 PAL 12,000
1002129 CAS 500
1002129 CS1 250
1002129 EA 1
1002129 INN 10
1002129 LAY 1,750
1002129 PAL 7,000
Column 1 is SKU nos, Column 2 is unit of measure and column 3 is quantity
What I want to know is how many cases(CAS) = one layer(LAY) when SKU is same.
E.g.: for SKU 1002121, one layer will be equal to 4 cases (2000/4)(LAY/CAS).
Hence I need a formula which satisfies three conditions
1. SKU must be the same
2. when column b=LAY and Column B=CAS then divide column C and show result in column D in layer's Row
Thanks for your help. Any suggestion is welcomed.
This expression is rather a complicated one:
=IF(B2="CAS",SUMIFS($C:$C,$A:$A,$A2,$B:$B,"LAY")/SUMIFS($C:$C,$A:$A,$A2,$B:$B,"CAS"),"")
(or
=IF(B2="CAS";SUMIFS($C:$C;$A:$A;$A2;$B:$B;"LAY")/SUMIFS($C:$C;$A:$A;$A2;$B:$B;"CAS");"")
if your locale uses as delimiters ; instead of ,)
Put in in the cell D2 and copy it to cells in the column D just bellow it.
Explanation:
IF decides if it is a cell where you want put the result.
The result is a quotient. Both the dividend and divisor use almost the same formula.
SUMIFS($C:$C,$A:$A,$A2,$B:$B,"LAY") details:
$C:$C is the range of numbers for creating the sum (in your case from only 1 number)
$A:$A is the range for making comparisons with:
$A2 a value to be compared with
Next 2 parameters have the same meaning as 2nd and 3rd, they make an another condition.
So there are 2 conditions. They are evaluated again and again for each pair of corresponding cells in the columns A and B (so A2 and B2, A3 and B3, etc.) and if both of them are satisfied, the corresponding cell from the 1st argument (i. e. C2, C3, etc.) are included to the sum (in your case at most 1 cell).
You could make a pivot table with your table as source. You would then put SKU in the filter and UOM in column fields. In the UOM you just filter the CAS and LAY. Then you get your numbers for CAS and LAY, which you just need to divide. You can also do the division in a pivot table calculated field.

Using Max function result in SumIFS Excel

I have a table like the image given above. There is another sheet which reports some information based on this data. I need the sum of Apples in the last week for a given month.
The answer for apples for 8 th month would be 14 assuming there is another record as Apples - 32 - 10 - 8.
So I would have to find max week number for a given month and then sum the quantity for Apples with max week number
The formula written is
=SUMIFS( C2:C300, A2:A300, H16, B2:B300, MAX(IF(D2:D300=MONTH(TODAY()-1),B2:B300)))
H16 contains the word "Apples"
Column A - Item
Column B - Week
Column C - Quantity
Column D - Month
Column H - Unique Items again..
MAX(IF(D2:D300=MONTH(TODAY()-1),B2:B300)) returns the correct max as 32 for month 8 but the formula returns the value as 0. If I put the max formula in aseperate cell and refer that cell in main formula, it works as expected. I am not sure why the result of max value is not being used for sumif function.
Your formula is good. all you need to do is to convert it into Array Formula. Just type the formula with Ctr + shift + enter.
{=SUMIFS( C2:C300, A2:A300, H16, B2:B300, MAX(IF(D2:D300=MONTH(TODAY()-1),B2:B300)))}
Actually, without array, the part IF(D2:D300 evaluates to #value error as Excel doesn't not know how to compare an array against one value.
Hint: Not sureif you know it already, but anyways, always use Formulas --> Evaluate Formula to pin-point an error in a formula.

Excel | Formula to find total amount in this situation

Assume that we are currently in the month March. I have a table with all the months and a list of products. Inside each column i have the number sales a product has made on that month, like so:
Notice i have a cell containing "Total until current month". I would require a formula to find out the total amount of sales of a specific product (product A for example) up until March (current month) as you can see with the manually typed 6, 1 in Jan and 5 in Feb.
I would usually do this by finding the sum of cell C4 and D5. But this should be 1 dynamic formula that is updating as we progress onto next month. So as an exammple, in April, it will find the sum of cell C4 - E5 (Jan - March) and update the value.
Is this possible?
Regards
Put a helper row above the month names that has the month numbers 1-12.
Then use SUMIFS():
=SUMIF($C$2:$N$2,"<=" &MONTH(TODAY()),C4:N4)
You could hide that row so it is not visible and not readily accessible.
In row 3 put month numbers. Now if in cell Q4 you have a month number that you want to relate to use:
=SUMIF($C$3:$N$3,"<"&$Q$4,C5:N5)
for sum of A and drag down for other products.
If you want to pick the product you want sum for and have it all in one cell, then assuming that in cell R4 you have your product name (e.g. "B") write
=SUM((C3:N3<Q4)*C5:N6*(B5:B6=R4))
and press ctrl+shift+enter.
The simplest solution is to leave E4 through N4 empty. Only put a value in E4 once March is complete and you have a value for March. This will allow a formula like:
=SUM(C4:N4)
for Product A

Excel: Trailing 3 month decline using data from a pivot table

(http://stackoverflow.com/questions/5283466/calculate-moving-average-in-excel seems to be somewhat related. I'm curious to know the non-vba way to do this.)
My my pivot table has source data that creates a count of how many sales a person had in the past 36 days. Each day os 1 column in the pivot table, and the persons name is on the row.
Some of these people did not have sales on day1, day2, etc, and may only have 3 days where they sold something on days 14,15 and 16. No matter what their sequence, I want to to find the most recent sale data (closest to the right edge of pivot table) and calculate three sales increases e.g. C20/C19 will be >1 if they had more sales on the whatever day C20 is. The increase ca nbe fond by subtracting 1 and changing to percent. The problem is, if a person only had sales on d10, d11, d12 then how can I put a general formula in Excel to say "look for the most recent consecutive sales, then calculate this ratio"? For a person who had sales in the past three days, that's easy. It will be chaotic to hardcode where to look for each sales value.
d1 d2 d3 d4...d7 d8 d9...d34 d35 d36 mostrecentincrease nextrecent
ant 1 5 7 7/5=1.4 5/1=5
bat ...10 11 12... 12/11=1.blah 11/10=1.1
cat 2 6 9 13
dog 19 20 20/19=1.blah 19/blank=0
elf 4 4/dnexist=0
i don't have excel here, but i hope this will guide you to the correct result (use , instead of ; if that is your list separator):
define sales as a range of values from d1 to d36 for a given row (or use actual ranges)
compute positions of the last values for each row using these array formulas (use ctrl+shift+enter instead of just enter after you write these formulas):
position_1 =max(if(sales<>0;column(sales)))
position_2 =max(if((sales<>0)*(column(sales)<>position_1);column(sales)))
position_3 =max(if((sales<>0)*(column(sales)<>position_1)*(column(sales)<>position_2);column(sales)))
retrieve the values:
value_1 =index(sales;position_1)
do some error handling (=iferror(...;0)) and the like...

Resources