Google sheets date formula and conditional addition for baby feeding - google-sheets

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.

Related

How to get only one of two repeating values

The Issue
In simple terms, I am trying to set a formula for an alternating pattern. The issue I keep running into is the fact that there are two alternating values, and Google Sheets doesn't like to repeat only one of those values without the other.
I have created an example sheet to demonstrate my issue. In Column A, a date is input. Column B and Column C then autofill with the day of the week and AM or PM respectively. Every other value in Column C alternates between AM and PM. I am trying to set it up so that the row is blank until a value in input in Column A. The issue comes when there is an odd number of Dates in Column A. Note that the alternating AM/PM pattern will never change.
What I've Tried
As seen in the image above, there are three main methods that I have tried. The data in C2:C8 is the desired result.
Method 1:
E2: =transpose(split({rept(join(";",{"AM";" "})&";",(roundup(counta(A2:A9)/2)))},";"))
F3: =transpose(split({rept(join(";",{"PM";" "})&";",(counta(A2:A9)/2))},";"))
These formulas work separately, and best represent what I am trying to accomplish, but I have not found a way to combine them to work together in one column.
Method 2:
H2: =transpose(split({rept(join(";",{"AM";"PM"})&";",(roundup(counta(A2:A9)/2)))},";"))
This is essentially the same as Method 1, but put into one formula. The issue here is that Google Sheets doesn't like to repeat half a number of times. So if the number of times to repeat (counta(A2:A9)/2) contains a half (i.e. 3.5), it will still round down to the nearest whole number.
Method 3:
J2: =ArrayFormula(TEXT(SEQUENCE(3),"")&{"AM";"PM"})
This one appeared most promising to me because when incrementing by one, it added one row, but I quickly ran into the issue where if I went over a sequence number of 2, it threw the error Array arguments to CONCAT are of different size.
References
I have used various search terms and websites to try to solve this, and have yet to find something that works. I may be missing something very simple, though, and hopefully this is a quick solution.
Example Sheet:
https://docs.google.com/spreadsheets/d/1I3EtptFLfDHpAQ8AR6Lwa01dSpJ3Cy8MTX1_OjHExSc/edit?usp=sharing
All my formulas are derived from the websites below:
REPT Function in Google Sheets
How to Repeat Multiple Columns N Times in Google Sheets
Delete everything in Col C (including the header) and place this formula in C1:
=ArrayFormula({"AM/PM"; IF(A2:A="",,IF(COUNTIFS(A2:A,A2:A,ROW(A2:A),"<="&ROW(A2:A))=1,"AM","PM"))})
The COUNTIFS finds the number of matches for the date "up to this row" for every row. Since that count will (or should) only ever be a 1 or a 2, the IF makes easy work of assigning "AM" or "PM" accordingly.
If I understand correctly it is enough to use ISEVEN function to alternate by rows:
=ArrayFormula(IF(A2:A,CHOOSE(ISEVEN(ROW(A2:A))+1,"PM","AM"),))

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.

Google Sheets Formula for Pulling Specific Values in Two Ways

I'm trying to do a couple of different things with a spreadsheet in Google and running into some problems with the formulas I am using. I'm hoping someone might be able to direct me to a better solution or be able to correct the current issue I'm having.
First off all, here is a view of the data on Sheet 1 that I am pulling from:
Example Spreadsheet
The first task I'm trying to accomplish is to create a sheet that lists all of these shift days with the date in one column and the subject ("P: Ben" or S: Nicole") in another column. This sheet would be used to import the data via a CSV into our calendar system each month. I tried doing an Index-Match where it used the date to pull the associated values however I found that I had to keep adjusting the formula offsets in order to capture new information. It doesn't seem like Index-Match works when multiple rows/columns are involved. Is there a better way to pull this information?
The second task I am trying to accomplish is to create a new tab which lists all the dates a specific person is assigned too (that way this tab will update in real time and everyone can just look at their own sheet to see what days they are on-call). However, I run into the same problem here because for each new row I have to change the formula to reflect the correct information otherwise it doesn't pull the correct cell when it finds a match.
I would appreciate any and all information/advice on how to accomplish these tasks with the formula combination I mentioned or suggestions on other formulas to use that I have not been able to find.
Thanks in advance!
Brandon. There are a few ways to attack your tasks, but looking at the structure of your data, I would use curly brackets {} to create arrays. Here is an excerpt of how Google explains arrays in Sheets:
You can also create your own arrays in a formula in your spreadsheet
by using brackets { }. The brackets allow you to group together
values, while you use the following punctuation to determine which
order the values are displayed in:
Commas: Separate columns to help you write a row of data in an array.
For example, ={1, 2} would place the number 1 in the first cell and
the number 2 in the cell to the right in a new column.
Semicolons: Separate rows to help you write a column of data in an array. For
example, ={1; 2} would place the number 1 in the first cell and the
number 2 in the cell below in a new row.
Note: For countries that use
commas as decimal separators (for example €1,00), commas would be
replaced by backslashes () when creating arrays.
You can join multiple ranges into one continuous range using this same
punctuation. For example, to combine values from A1-A10 with the
values from D1-D10, you can use the following formula to create a
range in a continuous column: ={A1:A10; D1:D10}
Knowing that, here's a sample sheet of your data.
First Task:
create a sheet that lists all of these shift days with the date in one
column and the subject ("P: Ben" or S: Nicole") in another column.
To organize dates and subjects into discrete arrays, we'll collect them using curly brackets...
Dates: {A3:G3,A7:G7,A11:G11,A15:G15}
Subjects: {A4:G4,A5:G5,A8:G8,A9:G9,A12:G12,A13:G13,A16:G16,A17:G17}
This actually produces two rows rather than columns, but we'll deal with that in a minute. You'll note that, because there are two subjects per every one date, we need to effectively double each date captured.
Dates: {A3:G3,A3:G3,A7:G7,A7:G7,A11:G11,A11:G11,A15:G15,A15:G15}
Subjects: {A4:G4,A5:G5,A8:G8,A9:G9,A12:G12,A13:G13,A16:G16,A17:G17}
Still with me? If so, all that's left is to (a) turn these two rows into two columns using the TRANSPOSE function, (b) combine our two columns using another pair of curly brackets and a semicolon and (c) add a SORT function to list the dates in chronological order...
=SORT(TRANSPOSE({{A3:G3,A3:G3,A7:G7,A7:G7,A11:G11,A11:G11,A15:G15,A15:G15};{A4:G4,A5:G5,A8:G8,A9:G9,A12:G12,A13:G13,A16:G16,A17:G17}}),1,TRUE)
Second Task:
create a new tab which lists all the dates a specific person is
assigned too (that way this tab will update in real time and everyone
can just look at their own sheet to see what days they are on-call).
Assuming the two-column array we just created lives in A2:B53 on a new sheet called "Shifts," then we can use the FILTER function and SEARCH based on each name. The formula at the top of Ben's sheet would look like this:
=FILTER(Shifts!A2:B53,SEARCH("Ben",Shifts!B2:B53))
Hopefully this helps, but please let me know if I've misinterpreted anything. Cheers.

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

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)

How to go from individual date/time log to "timeline" graph?

I have essentially a log file in a Google Sheets. Columns are "Date/time", "user", "asset accessed", and there will be multiple entries for the same date, though usually not time.
I'd like to use the timeline graph to show user activity, but the graph requires an aggregate view with one date (no time) per row, with a numeric count in second col. Is there a way using functions within Google Sheets to generate an aggregate "view" of this data and pass this to the timeline graph?
Well, I guess you'll have to create an auxiliary sheet, or just some columns with the summarized values for you chart.
From your description, I'll assume you're using 3 columns (ABC). Let's use columns D, E and F with the following formulas:
=ArrayFormula(Trunc(A:A))
=Unique(D:D)
=ArrayFormula(CountIf(D:D;E:E))
Since date values are actually a number (qtt of days since the epoch), and hours are decimals, the Trunc formula gets rid of the "time" part and leaves only the date. Just format the cells (apparently numbers) as dates and you'll see. Then Unique and CountIf do the summarizing.
There's surely different ways of doing this, perhaps more "elegantly", in a single formula. But I think that in this way it's more easy to understand and learn from. Also, you'll probably need to adapt the ranges to your actual columns positions (I hope that's not a problem).

Resources