Interpolation of months between two dates and calculating a sum using a fixed value for each month - google-sheets

In a spreadsheet I have a resource estimation for each project with the start and end dates. Every row holds a separate project. Similar to what's below:
I would like to interpolate the months between Start and end Go Live date and use the same effort for each month. Ultimately, I would like to use this in a pivot table to sum up the monthly totals. It would like similar to below (calculations done quickly by hand so please excuse errors):
I'd prefer to use any out of the box functionality but if necessary I can also code this. Any pointers would be appreciated.

There are many ways to accomplish this task.
You may use 3 formulas, look at the screenshot:
Here's the formula #1 to make unique list of Regions, it's in cell H2:
=UNIQUE(A2:A)
The formula #2 gives the list of dates, it's in cell I1:
=ArrayFormula(
EOMONTH(MIN(D2:D),COLUMN(OFFSET(A1,,,1,DATEDIF(MIN(D2:D),max(E2:E),"M")+1))-2)+1
)
And the formula #3 counts sums, it's in cell I2 and must be copied right and down:
=IFERROR(SUM(FILTER($F:$F,$D:$D<=I$1,$E:$E>=I$1,$A:$A=$H2)),0)

Related

Google Sheets Array Formula Match on Multiple Conditions, 1 being date that is less than or equal to

I am hoping someone can help me out.
I have 2 different datasets and I am hoping to replicate something like the maxifs function using an arrayformula so that I only need 1 formula and do not need to drag it down.
What I would like to do is return a value that matches a name, and the date is less than or equal to a date in the column. Basically the most recent value that matches those criteria.
I have added a picture below
DEMO FIXED
The maxifs formula I am trying to replicate in this case is: =maxifs(I:I, A:A, G:G, H:H, "<=" & B:B)
Sample Sheet: https://docs.google.com/spreadsheets/d/1mMMT1JbBMTAM0togUFQtctpY5FKzgVaP2_YKnALoHAE/edit?usp=sharing
Thank you in advance.
UPDATE:
I have this formula
=arrayformula(if(len(A2:A), vlookup(A2:A&B2:B, {H2:H&I2:I, J2:J}, 2, false),))
Which almost does what I want, however if there is no date matching i need the value from the next most recent date. Instead this returns an error.
Your new goal has nothing to do with your post. Your image values don't match your sheet, and you don't want a max or equivalent to MAXIFS at all now. So the entire post will be confusing to other contributors and future site visitors. Consider spending adequate time to rework your post question, image and spreadsheet to accurately reflect your new goal in a unified way.
That said, I've added a new sheet ("Erik Help") with a formula highlighted in green which accomplished your new goal as I understand it:
=ArrayFormula(IF(A2:A="",,VLOOKUP(A2:A&"~"&B2:B,SORT({G2:G&"~"&H2:H,I2:I},1,1),2,TRUE)))
ADDENDUM (based on additional comment from OP):
I've modified the formula as follows:
=ArrayFormula(IF(A2:A="",,IFERROR(IF(REGEXEXTRACT(VLOOKUP(A2:A&"~"&B2:B,SORT(G2:G&"~"&H2:H),1,TRUE),"(.+)~")<>A2:A,"no match",VLOOKUP(A2:A&"~"&B2:B,SORT({G2:G&"~"&H2:H,I2:I},1,1),2,TRUE)))))

Adding to a cells value based on two other cells

I'm wondering how I would go about adding to a cell based on two other cells.
For example, I'm creating a Google Sheets document to track profit & loss on certain things in an online game I play.
I'll try to explain this as best as possible.
If cell B71 is equal to the string in cell B7, increase the value in cell D71 equal to the number in cell D7.
However, the values will need to be compared to various other things depending on the item required.
For example, the string in cell B7 might change depending on what specific type of item is needed for that day as it does change daily.
I have cells near the bottom of the sheet which list the different type of item which will show the total amount of items used in that month.
I've tried to explain this a little better as requested below
I'm trying to make a spreadsheet that keeps track of the quantity of a specific item I use in a game for a daily task. This task can be done daily, and to keep track of profit & loss, I have created a spreadsheet to keep track of this.
So, each day, there are three different types of items (runes) that can be used in the machine to create an item called 'Vis Wax'. As Runes are cheap, creating the vis wax can generate a good profit. (I love working with data, hense the spreadsheet.
The image above shows what a daily section looks like. I input each type of rune (has to be 3), input the quantity used and the amount each rune is worth to create the total cost under Total.
Further down below, this table has been created
This will keep track of each rune and the amount used during that month.
So with that said, I'm looking for a solution so that if Air rune is entered in ANY of them slots with the QUANTITY used, it'll update that table accordinly (as well as the other runes that are used too). I've tried nested IF statements, but don't seem to have any luck. With the amount of checks that seem to be happening, I can't seem to find a working solution. As Air Rune might be in slot 1 one day, then slot 3 the next day. So it seems each cell in the Quantity Table will need to compare EACH cell in the daily section, to each rune type that can be used.
Hopefully that has explained it a little better.
Spreadsheet Link
https://docs.google.com/spreadsheets/d/1sYLpZJ46IpNk52gxMoJOIZsOCWToLkC4FF83RBncCf0/edit?usp=sharing
I would suggest you to use a different structure and take all the data from one day in one column, something like this:
In this way you will be able to extend the days keeping the formulas in a really simple way. Below, I will explain some useful formulas that you can use to lighten your work:
Day: =text(DAY(B2),"dddd")
Rune type: Check Data validation to create a drop-down list of your rune types
For counting how many runes have you used you can use SUMIFS function. It returns the sum of a range depending on multiple criteria. In your case, you need apply it three time per rune, as you can have the same rune in three different places. You see it with the following image:
The formula is: =SUMIFS($B$8:$H$8,$B$7:$H$7,A25) + SUMIFS($B$12:$H$12,$B$11:$H$11,A25) + SUMIFS($B$16:$H$16,$B$15:$H$15,A25). In this way you only need to write it once and you can fill the rest of the runes just dragging the mouse. If you need more days just change the column H with the last column that you want to take.
I assume that with all this information you can also keep track of your monthly statics easily. I suggest you to create a different sheet for each month.
I hope that my answer was useful, let me know if you have any doubt.
George, I agree with #fullfine, your data structure does not seem ideal for data analysis. And it doesn't seem that efficient for data entry either, with the sideways scrolling (at least on my screen).
But I recognise that you might not want to change it, perhaps having specific reasons for that layout, and having invested time in it. So I offer this formula as an alternative, which basically pulls the needed cells from your existing sheet, and comes up with the totals you'll need.
=QUERY(QUERY({B7:D9;G7:I9;L7:N9;Q7:S9;V7:X9;AA7:AC9;AF7:AH9;
B20:D22;G20:I22;L20:N22;Q20:S22;V20:X22;AA20:AC22;AF20:AH22;
B33:D35;G33:I35;L33:N35;Q33:S35;V33:X35;AA33:AC35;AF33:AH35;
B46:D48;G46:I48;L46:N48;Q46:S48;V46:X48;AA46:AC48;AF46:AH48;
B59:D61;G59:I61;L59:N61},
"select Col1, Col2, Col3*Col2 where Col1 <>'' order by Col1 label Col3*Col2 '' ",0),
"select Col1, sum(Col2), sum(Col3) group by Col1 label sum(Col2) '', sum(Col3) '' ",0)
The same formula can be used for each month, since it always totals all 31 days, even if the month has fewer days.
For your Rune table in the Statistics sheet, you only need the firsts two columns, so you could delete the "sum(Col3)" from the last select statement.
For your smaller financial table, you would take the sum of the Col3 produced by the above formula, ie. the total value of all the runes used. A similar formula would be used to collect the count of the wax produced, its value, and the profit/loss for each day. This would let you complete the financial table.
If you do decide to go with this approach, and want any help with completing the tables, or the formulas, please share your sheet so "anyone can edit it", to make it easier for me to assist you.

Using a Named Range to identify worksheets to use a SUMIFS on a to add an array of data

Below is a sample of the Google Sheet I'm working on:
https://docs.google.com/spreadsheets/d/1LDsfn_FMdUSfuFZAyuXf5gdlOSN9yLqhT1RY8aX7Nfs/edit?usp=sharing
On the spreadsheet Team Totals, I'm trying to calculate all the sales based on the date, the type of sale, and the program type starting from Row 27.
The problem I have run into is that the Named Range, Consultants, only pulls the data from the first cell of the Named range (Octo). What I want is for a formula that will pull the data of the selected range from each entry in the named range and sum them together.
For reference, I put what the proper values should be starting from Row 33.
The closest example I have seen was from this website: https://www.got-it.ai/solutions/excel-chat/excel-tutorial/sumif/sumif-across-multiple-sheets
However, I get the same problem that only the first cell in the named range gets pulled.
I feel like I'm missing something simple, but I have been bouncing it around my head for hours and can't figure it out. Any help is greatly appreciated.
So after trying to figure out a way not to use an iterative process, I folded and did this:
=arrayformula(SUMIFS(INDIRECT("'"&$B$4&"'!F6:F100"),INDIRECT("'"&$B$4&"'!D6:D100"),$B$2,INDIRECT("'"&$B$4&"'!E6:E100"),E$27,INDIRECT("'"&$B$4&"'!A6:A100"),$A41)+
SUMIFS(INDIRECT("'"&$B$5&"'!F6:F100"),INDIRECT("'"&$B$5&"'!D6:D100"),$B$2,INDIRECT("'"&$B$5&"'!E6:E100"),E$27,INDIRECT("'"&$B$5&"'!A6:A100"),$A41)+
SUMIFS(INDIRECT("'"&$B$6&"'!F6:F100"),INDIRECT("'"&$B$6&"'!D6:D100"),$B$2,INDIRECT("'"&$B$6&"'!E6:E100"),E$27,INDIRECT("'"&$B$6&"'!A6:A100"),$A41)+
SUMIFS(INDIRECT("'"&$B$7&"'!F6:F100"),INDIRECT("'"&$B$7&"'!D6:D100"),$B$2,INDIRECT("'"&$B$7&"'!E6:E100"),E$27,INDIRECT("'"&$B$7&"'!A6:A100"),$A41)+
SUMIFS(INDIRECT("'"&$B$8&"'!F6:F100"),INDIRECT("'"&$B$8&"'!D6:D100"),$B$2,INDIRECT("'"&$B$8&"'!E6:E100"),E$27,INDIRECT("'"&$B$8&"'!A6:A100"),$A41)+
SUMIFS(INDIRECT("'"&$B$9&"'!F6:F100"),INDIRECT("'"&$B$9&"'!D6:D100"),$B$2,INDIRECT("'"&$B$9&"'!E6:E100"),E$27,INDIRECT("'"&$B$9&"'!A6:A100"),$A41))
This formula allows me to cut and paste it to various cells easily, and does the job I need it to, while still using the indirect reference so I can change names without breaking the formula (granted I change the worksheet name as well).
I will need to edit this to include all possible worksheet amounts I can forsee, but once it's done, I won't have to tinker with names anymore.
I'm not happy with this answer, as it creates a really long and ugly formula, essentially repeating the same formula 20 times, but it does work. I feel like there should be an easy function that would be able to do this.
This will return Total sales:
=if(isna(ArrayFormula(QUERY({Lo!$A$5:$F; Tulio!$A$5:$F;Ya!$A$5:$F; Miguel!$A$5:$F;Kevin!$A$5:$F; Octo!$A$5:$F}, "select sum(Col6) where Col1=date '"&TEXT(A28,"yyyy-mm-dd")&"' label sum(Col6) ''",0)))=TRUE,0,ArrayFormula(QUERY({Lo!$A$5:$F; Tulio!$A$5:$F;Ya!$A$5:$F; Miguel!$A$5:$F;Kevin!$A$5:$F; Octo!$A$5:$F}, "select sum(Col6) where Col1=date '"&TEXT(A28,"yyyy-mm-dd")&"' label sum(Col6) ''",0)))
BTW, I get Total sales of $0, $615.50 and $2,498.00
The best way to pull data from a lot of unknown tab names without a script is to actually CREATE the tab names beforehand. On your sheet it looks like you're anticipating/making space for 21 employees. If I were you, I would just create 15 more tabs named Temp7,Temp8,Temp9... etc. Then you can just "hide" those tabs. Then a formula can be built in your totals section that will easily stack all the tabs up using an array literal and a QUERY( { } ) to add up the totals for you without all this INDIRECT() nonsense that you have been going through to pull from the individual tab names.
Would pre-adding tab names be something you were interested in if I could show you the formulas to make the totals easy to calculate?

COUNTIF with IMPORTRANGE with date range and unique ID criteria

I haven't been able to find a solution to get this formula to work after multiple days of searching. The google spreadsheet we use is large and used by many people so I would like to keep this in a separate google sheet using IMPORTRANGE.
Data Needed:
Count of assignments a specific user completed within 7 days and after 7 days based on a start and end date.
Where I'm running into issues:
I simplified the equation by using a small data set in the same sheet to see the main issue. When giving a range for the user # the formula doesn't work anymore. When only comparing it to one user # at a time it does.
For example:
This doesn't work:
=COUNTIFS(C2:C-B2:B,"<7",A2:A,E2)
This one does but needs to have the range for the table to work:
=COUNTIFS(C2:C-B2:B,"<7",A2,E2)
I might be going about this all wrong. Any help I could get is much appreciated.
E2: =UNIQUE(FILTER(A2:A, A2:A<>""))
F2 and drag down: =COUNTIF(ARRAYFORMULA(DAYS(FILTER(C$2:C,$A$2:$A=$E2),FILTER(B$2:B,$A$2:$A=$E2))),"<=7")
G2 and drag down: =COUNTIF(ARRAYFORMULA(DAYS(FILTER(C$2:C,$A$2:$A=$E2),FILTER(B$2:B,$A$2:$A=$E2))),">7")

Google sheets date formula and conditional addition for baby feeding

I'm looking for an easy way to account my son's food intake. The trouble is, all of the forms we've used to date are arduous when trying to collect data straight into spreadsheets. So I thought we could use an IFTT/Do button.
A couple problems I need help with:
IFTTT inputs the data as text: how do I use the DATE function to reformat the cell data for each date?
The "button" we're using represents 30 mL of milk but in a single meal he may eat much more - so we're pressing the button multiple times. What array formula can I use to add all formula for each day?
Here's a link to a sample spreadsheet so far. https://docs.google.com/spreadsheets/d/1ds_IvgS5JWuFmsEipk-wUcsfGQVSVD1tXPydDCoT7Xo/edit?usp=sharing
I hope you enjoy this special time.
I would leave column A alone, probably you get no control on that.
But for column B, if you get to, I follow your lead on the condition, but I would want numbers for the results so I can do math on them, so =ARRAYFORMULA(if(A2:A>"0",30,0))
I introduced a column C for Dates and a Column D for times and did the following in C2 to get them:
=arrayformula(if(isblank(A2:A),"",SPLIT(A2:A," at ",false))).
To make these look nice, I formatted the respective columns as dates and times.
In column E I wanted the various dates, so I wrote in E2,
=unique(C2:C)
Then to get the sums per date I had had a really gross QUERY for SUM(B) where C = Date..., and then I saw the comment with the sumif idea. So in F2 you can put the following and drag down as needed:
=sumif(C2:C,E2,B2:B)
and you have your totals by day.

Resources