OnEdit or Time based triggers to check one cell then edit another - google-sheets

My scripting skills are not the greatest but I can not figure out how to accomplish what I need to with just functions inside of Google Sheets.
My sheet looks something like this: https://docs.google.com/spreadsheets/d/1R6YJIR37wtOt8ZknSdMQPFFp0Llf_LHpmGCV32iQY00/edit#gid=1213399830
I have form responses being brought into the second tab via the Indirect function and are then modified with a ArrayFormula function to convert everything to the correct unit of measure and the summed to keep everything on the same row. All of this could be altered if needed.
I then have a column that is totaling inputs in other columns to give me my on hand inventory. We'll call this TotalsColumn.
What I am attempting to achieve is to make a script that checks the form responses, then either with:
OnEdit (which if I understand correctly does not work for information being ported in) and then alter the corresponding cell in the TotalsColumn.
or if not possible, then
With a time based trigger checking the ported information to see if there is a new entry if I don't sum it with a last function or something, or if the information remains summed (which seems easier to me) then to check if the sum is greater than it was last time it was checked and alter TotalsColumn.
The alter to the TotalsColumn, regardless of which method used, will always be a static number and I am pretty sure I'll need to make a script for each of my different inventory items but that's fine if I can just figure out a way of making this happen.
Thank for your time and any information you can provide.
Please feel free to point me to another thread where I can start to piece together a solution, I just could not find anything that related closely enough to my question or find a good jumping off point.

What happens in this situation?

Related

How to column sum in Airtable like excel?

I am designing airtable.
I met some issue.
I need to column total sum like excel.
For example:
Column1 Sum(Column1)
1 1
2 3
4 7
6 13
Like this. What is solution?
Thank you.
Airtable is not a spreadsheet but a relational database, the behavior you're looking for isn't straightforward to reproduce because it's not meant to work like rows matter and aren't anything but a temporary sort - they don't, so they're not.
I know you were probably hoping for a better answer than another question, but I simply have to ask - why do you need to do this inside Airtable? Why not just use one of dozens readily available and entirely free spreadsheet/table solutions?
Generally speaking and especially if you don't need to manipulate that data afterward (a big if), Airtable already does the calculation you want on the fly and has it stored as part of its metadata.
The row-by-row addition would be doable using a combination of one autonumber field, a linked record (to another table actually polling for values) and a rollup returning data. I've done this back in the day once or twiCe and it was always an overengineered mess, even if I only had to deal with small integers like from your example.
There's Google Drive sync beta ongoing at Airtable right now. Just get that and do the calculations you need elsewhere?
The alternative is the Scripting app, but that might prove crippling in terms of how it could affect your automations quota. And recalculating fields by "hand" is... not sophisticated, to put it mildly.
But hey, don't take my word for it; Curiosity and nostalgia got the better of me so I gave this futile effort another go on your behalf, here's my best take at such an overengineered mess of a field-wide sum function that's wildly annoying to use but at least doesn't take all day to update records, even if presented with hundreds or thousands of inputs.
So, yeah... right tool for the job and all that: this ain't it, chief, but be my guest. You can clone the base from the Universe and everything will be ready for testing, just keep creating new fields or deleting the exiting few ones, then hit the "Run Script" button of the only app hooked into the base to see it recalculate the sum.
Dumping the code here as we, if anyone wants to set up a new testing environment manually:
let table = base.getTable('Table 1');
let query = await table.selectRecordsAsync()
let cellsToAdd = [];
let sum = 0;
const keepSumming = x => sum += x ;
query.records.forEach( x => cellsToAdd.push(
{
"id": x.id,
fields:{
"Column1":x.getCellValue('Column1'),
"Sum":keepSumming(x.getCellValue('Column1'))
}
}
));
//Airtable limits us to 50 table mutations per request, hence the splicing
while(cellsToAdd.length>0){
await table.updateRecordsAsync(
cellsToAdd.splice(0,50)
)
};
There appears to be a feature built-in to Airtable for this now. In the desktop app, at least, take a look down at the bottom of each column below all rows. There is a context menu for the column, in which Sum is one of several options.

How do I get a cell to retain text, after the cell it pulls from changes text?

This question will have two parts. If you're willing to help me out, feel free to address whichever chunk you've got the time or interest for. Thanks in advance.
Assume there are two cells in a spreadsheet, the first (A1) has the text hello inside, and the second (A2) has =T(A1), so they now both say hello. If I want to change the text in A1, but want the text in A2 to continue to read hello, is there a way to automate this?
For some context, this is part of a larger project where I want to create a column of stock tickers that I like. Ideally, I could type the ticker name into a cell, check a box if I want to track it, and it would automatically add itself to a column. Where the first part of this question becomes relevant is that I would then move on to another stock, deleting the first ticker I wrote, but still wanting it in my column.
The second part of the question is about making the column. My instinct would be to use the =ARRAYFORMULA function, but that draws from a column to begin with, so I'm a little bit stuck.
Thanks
answer for Q1:
no, not possible unless you hardcode A2 as:
=T("hello")
or you use a script to remember your value but in that case, the A2 will host a custom function instead of the formula you mentioned
ofc what you are mentioning with those tickers, checkboxes and moving values around it's completely doable with a script
answer for Q2:
it depends on the formulae you use. not all formulas are supported under ARRAYFORMULA

Transform comma separated google form answers to multiple lines in spreadsheet

I have made a google form to which some answers are formatted as comma separated strings inside the automatically populated google spreadsheet. I would like to read from this sheet to another sheet and reformat the answers so that each comma separated answer is shown on a new row. I have tried to apply an ARRAYFORMULA that reads from the original sheet and then use a solution that uses SPLIT and TRANSPOSE the cell content, however combined with the ARRAYFORMULA this fails since it would overwrite contents in other cells.
Here is an example spreadsheet with the responses, a solution sheet, and a desired results sheet. https://docs.google.com/spreadsheets/d/1r_l5fVJ9lGfpubO2o3pXicV7JlZWmANjwSgNi7_DL0A
Any suggestions for how I can achieve the end result?
Okay, I assume this isn't really what you want, but visually it looks okay...
Try this formula:
={{'Form responses'!A2:A3},ArrayFormula(regexreplace('Form responses'!B2:E3,", ",CHAR(10)))}
Then format the cells so that the cell contents are TOP-aligned, instead of the default BOTTOM-aligned.
Realistically, I imagine that you want each question answer split into multiple cells. But if your data responses really contain letter values separated by commas, as you've indicated, you can still search through those cells to find whether an answer contains a certain value. It all depends on why you want the results structured the way you do.
If you can clarify what you want to do with the form results, instead of just appearing vertically for each question, perhaps we can provide a full solution for that requirement?
UPDATE1:
Okay, I may be getting close. I can get your data transformed to look like the following:
This would let you do the analysis that you want, by searching for Q.1 (question 1 responses) in the first column, and then all the answers in the third column, along with the owner in column 2. And from this, it will also definitely be possible to put the results in the exact form you want. It just may take an intermediate step.
UPDATE2:
Okay, I think I have something you can use. I can convert your data to either of the following two layouts.
The one on the right is closest to what you asked for, with the exception that the answers on the right are bottom aligned, with blanks above. But you can still process them for analysis, with queries. I honestly think having the user identifier (email address) on each row would make things simpler, but I can provide it either way.
The layout on the left is more of a traditional database layout, and would make analysis very simple. Each row has the date and email identifiers, the question number, and the answer (or one of the answers) to that question, from that user.
If this is helpful, it might be best if you enabled your sample sheet to allow us to edit it, to enable me to implement it in your sheet. But here is my sample sheet, in case anyone wants to look through it. Note that the main formula to reformat the data, in Solution!B3, could benefit from a lot of cleanup, and is probably nowhere near the best way to achieve this. Just throwing up one possible solution...
I'll try to add some explantion for the formula at some point, but ask if you have any questions.

Creating Dynamic Sheet Cell Reference List for pulling numbers to SUM

I've been working on building a data analysis sheet, which is quite verbose at the moment and a bit more complicated than it should be as I've been trying to figure this out. Please note, I work doing student data in a school.
Basically, I have two sets of input data:
Data imported from a CSV file that includes test data and codes for Common Core Standards and the questions tied to those standards as a whole class summary
Data imported from a CSV file that includes individual scores by question
I am looking to construct 2 views:
A view that collates and displays data of individual standards per student that includes a dropdown to change the standard allowing a teacher to see class performance by standard in a broad view. The drop-down is populated dynamically from the input data (so staff could eventually dump data and go directly to reports)
A view that collates and displays data of individual students broken down by performance on each standard allowing a teachers to see the broader spectrum for each student. The student drop-down is populated from Source list 2.
I have been able to build the first view, but am struggling with the second. I've been able to separate the question codes and develop strings of cell references to the scoring data, including a dynamic reference to the row the selected student's score data appears on in the second source set from above.
I tried to pass through an indirect() formula into a sum() so as to process for a mean evaluation, and have encountered errors. I think SUM() doesn't process comma-separated cell reference lists from Indirect() [or in general] or there is something that I am missing to help parse it. Here is the formula I have tried:
=Sum(vlookup(D7,CCCodeManip!$A:$C,3,false))
CCCodeManip!C:C includes the created text (based on the dynamic standards and question codes, etc), here's an example of what would be found there:
'M-ADI'!M17, 'M-ADI'!N17, 'M-ADI'!O17, 'M-ADI'!P17, 'M-ADI'!Q17, 'M-ADI'!R17, 'M-ADI'!J17
I need these to be dynamic so that teachers can input different sets of standards, question, and student data and the sheet automatically collates and reports it in uniform ways (with an upward bound of 20 standards as I currently have it built)
Here is a link to the sheet I built, with names and ID anonymized. There's a CRAP TON of sub-tabs, and that's really just being able to split apart and re-combine data neatly without things error-ing out due to data overlapping, aside from a few different attempts and different approaches to parse the cell reference strings.
The first two tabs are the current status of the data views. I plan to hide a bunch of the functional stuff that is there to help pull data accurately.
The 3rd and 4th tab are the source data sets. 5th is a modified version of source data that allows me to reference things better, and I've tried to arrange the sheets most relevant towards the front of the set.
https://docs.google.com/spreadsheets/d/1fR_2n60lenxkvjZSzp2VDGyTUO6l-3wzwaV4P-IQ_5Y/edit?usp=sharing
Some have a different approach? I am aware that I might be as far as I cn go with this and perhaps should consider scripts - my coding experience is a bit out of date and my strength is more with the formulas, but I can dig into things with some direction, if anyone can help.
Ok so I noticed something.
It seems the failure is in the indirect reference:
=indirect(CCCodeManip!C3)
The string I am trying to parse via indirect is going to be generated into something like this, dynamic from reference to other data:
'M-ADI'!M17, 'M-ADI'!N17, 'M-ADI'!O17, 'M-ADI'!P17, 'M-ADI'!Q17, 'M-ADI'!R17, 'M-ADI'!J17
The indirect returns the error that the above string is not a cell reference with the #REF code.
Can someone give me a clue as to what is causing this? I am going to dig into the docs on Indirect() from google and will post anything that I find.
Perhaps it is that indirect() can't handle lists, but only specific references and arrays, which may require me a to build a sheet to do the SUM formula on for each question set (?)
So I think I figured it out, but i Ended up parsing the data differently, basically doing the sum based on individual cell references and a separate sum formula, bypassing the need to do it all at once, it jsut makes my sheets a lot dirtier! I am eventually going to see if code could do it better if I need to, but this is closed for now.
Basically, I did individual cell references to recall scores in a row, then used a separate SUM formula, and created references / structures to be able to pull those sum() results. Achieves the same end, but with extra crap on the sheet.

How do I make changes to a named range in google sheets propagate immediately?

I'm using Google Sheets to calculate my goals for weight lifting. Different workouts are based on different percentages of my high score for each lift.
I had been calculating each day's plan with something like "=CEILING((0.8*A3/5), 1)*5" to represent 80% of whatever the hell was in A3, rounded to something divisible by five. This was not maintainable.
What I'm working on now is using the script editor to provide custom functions. "=FIVES('bench')" gives me my bench press progression for five reps.
That works great, except for when I change values. I put a named range on each of my max lifts so I could call getRangeByName get the value by name instead of by cell coordinates. But the functions I made don't get called again so I keep seeing stale values, even after refreshing the page.
I found another post suggesting that getRangeByName had a second arg which could be set to now() to refresh the cache now. Tried that and it looks like that was out of date. I haven't found any other info on a named range being cached.
How can I tell my script that it needs to re-run when a named range gets updated? Is there some sort of observer/listener/watcher in sheets? If not, I'm open to techniques - named ranges were just the first thing I bumped into for naming my variables.
Google's script caching was never going to allow that to work without shenanigans. The expectation is that foo('bar') will be deterministic, always returning the same thing. I'd been passing the named range's name, hoping I could use getRangeByName and using the name as a label.
Instead I'm just using the range as an arg and passing a second string as a label: foo(bar, "Bar label"). It's a little more verbose, but much less so than the stuff I was trying to trick the script server with. Don't fight the framework, folks.

Resources