Populating Dates and Numeric Values from one table into another table - excel

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.

Related

Multiple Complex IF conditions using 3 Tables

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.

Find row when Cumulative sum reaches certain value with condition

I have a table with 3 columns Date, Item and Number. Each row indicates how many items of each Item was received on that date. I am trying to find the date on which cumulative sum reaches 100 or more in that month. Each month will have a target for each item which will be saved in another sheet but for simplicity we can assume that its a fixed number of 100.
Example Data:
Date Item Number
1/2/2018 A 10
2/2/2018 B 10
2/2/2018 A 15
5/2/2018 C 25
6/2/2018 A 50
7/2/2018 B 10
7/2/2018 C 10
8/2/2018 A 25
9/2/2018 A 20
I am looking for the formula which should act on the data similar to above and give the result as 8/2/2018 which is the date on which the cumulative sum for Item A reached 100.
Each month will have different target number, and will have different number of entries.
I have tried using SUMIF and adding a additional column etc but this data is just part of a big data and each item limit is saved in a different sheet etc which is not easy to merge. Thanks in advance for help.
In Excel only, you can use Offset to develop an array of items and numbers containing 1,2,3...9 rows and then SUMIF to add each of them up. Then use Match to find the first one =100 and Index to find the matching date (in F2):
=INDEX(A2:A10,MATCH(100,SUMIF(OFFSET(B2,0,0,TRANSPOSE(ROW(A2:A10))-ROW(A1)),"A",OFFSET(C2,0,0,TRANSPOSE(ROW(A2:A10))-ROW(A1))),0))
Must be entered as an array formula using CtrlShiftEnter.
EDIT
To find the first sum which is >=100 (in G2):
=INDEX(A2:A10,MATCH(TRUE,SUMIF(OFFSET(B2,0,0,TRANSPOSE(ROW(A2:A10))-ROW(A1)),"A",OFFSET(C2,0,0,TRANSPOSE(ROW(A2:A10))-ROW(A1)))>=100,0))
Sum which reaches exactly 100
Sum which does not reach exactly 100 (the number in row 9 has been changed to 24):

Quantifying conditional duration of values in excel

I am trying to analyze blood pressure that is taken every minute, and determine how long the values are within a certain range, consecutively. I have the data set up in excel for the moment. I have color coded the values based on the ranges I would like to quantify. I know that if I do a simple "=countIF) function I can get the total number of times these values meet the criteria. But what I want to do next is quantify for how long the values fall within a specified range, consecutively.
This shows values in columns in excel, where each column is a different patient, and the heat map are the value conditions to help me visualize if certain thresholds occur for longer times than others. But I want to find a way to quanitify this in excel, if possible. Any help would be much appreciated.
The final result I am looking for is to be able to measure how much time each patient sustains a specific category of blood pressure to know if certain ranges are more prolonged than others (e.g. blood pressure is between 120-130 for 30 minutes). So in the spreadsheet above, assuming each cell is a 1-minute bin, for column HU, BP is between 120-130 for 3 minutes (rows 2-4), and again for 16 minutes (rows 6-22). In column HS, blood pressure is above 140 (black) for 7 minutes.
I want to find a workflow to quantify these durations so that I can get a summary of the number of consecutive 1-minute bins (each cell) at a specified range/threshold for each patient (column)
First, I would create another sheet -- let's call it "Thresholds" -- with thresholds of bloodpressures in ascending order in column A.
Put a category number next to each value (in column B)
For example:
0 0
90 1
100 2
105 3
110 4
115 5
120 6
125 7
... etc.
Back in the other sheet, add a new column next to each bloodpressure column. So you
would have a new column HR next to HQ.
Put there a formula that looks up the category for the value in HQ, from sheet "Thresholds".
You can use VLOOKUP for that. For example in row 2:
=VLOOKUP(HQ2, Thresholds!$A$1:$B:$1000, 2)
Then add yet another column, HS it will be.
In there make a running count for same category rows, like this (for row 2, I assume you have used row 1 for column titles):
=IF(HR1<>HR2, 1, HS1+1)
Drag down this formula to the column. This formula checks if this row has a different category of blood pressure than the previous one. If so, it
sets the counter to 1 (it is the first instance in this running series). In the other
case it takes the value of the counter in the previous row and adds 1 to it.
Repeat this for the other columns (inserting 2 new columns next to each).
This will already give you a start for further analysis.

Issues with VLOOKUP in Excel

I have a tax table in one sheet that has a list of tax values. For example:
Sheet1: Tax Tables
A B C
1 Min Max Taxed
-------------------
2 50 100 10
3 100 200 20
4 200 300 30
In another sheet I have a gross income value of say 120 in cell A1. What I want to do is have a vlookup (I'm assuming that's what I should use) that checks cell A1 to see if it's between the Min and Max and then outputs the taxed amount in B1.
Sheet2: Income
A B
1 Gross FedTax
-----------
2 120 Value from Column C goes here
I already have the sheet in Tax Tables set up with named spaces A:C=Min and B:C=Max
I tried doing this:
=AND(VLOOKUP(<A1,Min,3,False),VLOOKUP(>A1,Max,2,FALSE))
But not even close...
I just want to check column A in the first sheet to see if it's less than the the value in the second sheet, and check column B in the first sheet against the value in the second for if its more, then put the value in column C in the first sheet into the cell next to the value in the second sheet.
To use a VLOOKUP, put your maximums and minimums in the same column.
Then use the TRUE argument, which means it looks for the next value that matches. Assuming the value you're looking up in D2, you'd put a formula like this in E2:
=VLOOKUP(D2,$A$2:$B$5,2,TRUE)
First of all it is unclear what you would apply when the amount is exactly 50/100/200/300/... So i decided to include the lower limit in the interval and exclude the upper limit.
For this problem I would use a sumifs like this (you have to decide on which side to put the equal sign:
=SUMIFS(Sheet1!C:C;Sheet1!A:A;"<="&A1;Sheet1!B:B;">"&A1)
This would only take those elements in column C that have a value in column A smaller than or equal to 120 and a value in column B greater than 120

Top third, next third of items by sales

I have an excel sheet as shown below. I need to get the top third/ next third items by sales count. Is there a way to get this done in Excel?
Item Count
1 100
2 90
3 80
4 60
5 55
6 50
7 45
8 35
9 25
Dividing into 3 buckets, so 540/3 = ~180 items in each –
Bucket 1 – Items 1 and 2 (Count = 190)
Bucket 2 – Items 3, 4 and 5 (Count = 195)
Bucket 3 - Items 6, 7, 8, 9 (Count = 155)
There are multiple ways to achieve this. Assuming that your Item and Count data are in columns A and B, then the shortest path is to use the following formula in cell C2:
=ROUND(3*SUM($B$2:$B2)/SUM($B$2:$B$10),0)
After entering that into C2, select that cell and drag down the right-bottom corner of the cell all the way to the last row. Note the $ sign that is "missing" on purpose before the second 2. That takes care of the auto-fill behavior needed when dragging down the corner.
If you are allowed to use a helper column, you can create a computationally more efficient method using following layout:
If you want to, you can hide column C. It contains cumulative values of the different sales counts. Cell C1 is set to 0, cell C2 contains the formula =$C1+$B2. Column D then approximates the buckets by using the formula =ROUND(3*$C2/$C$10,0) in cell D2, and then again dragging down the bottom-right corner. This might be the better approach if you have many rows on your sheet.
Note that both solutions yield the same results. The value in one or more buckets could become 0, which is not exactly right. That can be avoided using ROUNDUP in stead of ROUND, but since you have not indicated clearly where you want the boundaries of the buckets to fall exactly in different situations, I thought I leave that as an exercise to you :-).

Resources