I am maintaining a tracker of sorts for enterprise wide. Recently my manager came to me with a request that he wants to see daily change against each of the respective business unit. The challenge is information is updated in real time and I don't have a time stamp to calculate the instance to be taken for calculation. Is there any way in Google Sheets to do that ?
Pasting the image below for better understanding
enter image description here
Make a short script that copy as values 'Cases (Live)' to 'Previous day Instance' column. And then put a trigger on that function to be activated each day at 23:59. Put a link to your project to go further. Example :
function histo(){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('my Sheet');
var range = sheet.getRange('B5:B9');
range.copyTo(sheet.getRange('D5'), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
}
to define a trigger based on time
function createTimeDrivenTriggers() {
// Trigger every day at 06:00AM CT.
ScriptApp.newTrigger('histo')
.timeBased()
.everyDays(1)
.atHour(6)
.create();
}
Reference:
Installable Triggers
Related
This question already has answers here:
How to stop / freeze / pause volatile RAND / RANDBETWEEN / RANDARRAY?
(2 answers)
Closed 9 months ago.
Any expert know to auto generate a random number every certain days later?
Example:
On every Monday, Google Sheets will auto change with a new random number:
https://docs.google.com/spreadsheets/d/1K8fJbRGRVB2Pv_X4MQT8WQgPkJfRPFq-apb7M61t6c8/edit?usp=sharing
Use Google Apps Script
I recommend using Google Apps Script because it has a time-dependent installable trigger feature. You may use the following script:
function randomNumber() {
var min = 10000; //Set minimum value
var max = 99999; //Set maximum value
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var num = Math.floor(Math.random() * (max - min + 1) ) + min; // The formula
ss.getRange("B2").setValue(Math.round(num)); //Assigns the random value to B2.
}
Afterwards, you can set an installable trigger with this setup:
Please take note of the important settings for this trigger setup:
Choose which function to run - the name of the function used
Select event source - set to Time-driven
Select type of time based trigger - set to Week timer
Select day of week - set to Monday (based on your example)
Select time of day - anytime you want the script to run(default value is Midnight to 1am)
If you do not know how to create an installable trigger, you may follow this tutorial video on YouTube: Google Apps Script Triggers Explained. You may skip to 9:42 (How to add installable triggers part).
Output
After saving/running the script and adding the installable triggers, the spreadsheet is expected to update cell B2 every Monday (Midnight to 1AM based on the current installable trigger setup).
References:
Math.random
Installable Triggers
First time posting.
Our fire response agency just moved to Cognos 11 after qRep. I know little to nothing about SQL, modules, cubes, or data analytics, but I'm one of the few in our agency that can write an excel function so I guess I am considered the in-house data expert.
With that in mind, I need some help.
I want to compare a calculated result (time interval) to a static goal. For instance, if the calculated result is 01:00, how do I express a static goal of 01:20 as a time interval to make the calculation work?
Here is the formula I used for my "Static Goal" column:
IF([Inc Cat]='EMS') then ('60')) else
IF([Inc Cat]='FIRE') then ('80')) else
NULL
I need to convert the 60 and 80 above as seconds so I can compare a calculated time interval to these values.
I appreciate any help, but please review the second sentence of this post prior to replying.
Solved. I removed the single quotes and wrote out the complete time.
IF([Inc Cat]='EMS') then (0 00:01:10.000) else
IF([Inc Cat]='FIRE') then (0 00:01:20.000) else
NULL
I am creating a google sheet that feeds from a form. I want to capture the timestamp in a separate cell when another cell is changed. I can get it to display the time now but I need it to be in military time.
var timezone = "GMT-4"
var timestamp_format = "hh:mm:ss"; // Timestamp Format.
I expect the output to say 13:15:55, but the actual is 1:15:55.
Google's App Script uses the standard JavaScript Date object when returning forms. Here is how to get what you want from a Date object.
var resultFromForm = ...
var time = resultFromForm.toTimeString().substring(0, 8);
you can just change internal formatting like:
I want to achieve following on the google spreadsheet :
Let's say I want some of my cells to take the value of another cell at specific dates and times.
The value is actually just a background color, but if that's a problem, it could be some text, even if I prefer the background color.
For example in this sheet :
https://docs.google.com/spreadsheets/d/15icn5bi-wZY1HZeLwpoM2Z_XrKOqydUH1BgdDGEEqLM/edit?usp=sharing
Let's say I want my cells A3, A5 and A6 to become like the cell F1 every monday, wednesday and friday at 6:30 am GMT+1.
Then the user can modify it but every Monday, Wednesday and Friday at 6:30 am GMT+1 the value is reset to the value of F1.
You can do this with this code and a time based trigger.
function colorCells() {
var ss=SpreadsheetApp.getActiveSpreadsheet()
var s=ss.getSheetByName("Feuille 1")
var c1=s.getRange("F1").getBackground()
s.getRange("A3").setBackground(c1)
s.getRange("A5").setBackground(c1)
s.getRange("A6").setBackground(c1)
}
On the scrips menu, select Edit>Current project's triggers.
Click to add a new one. Select the colorCells function, Time-driven,
Week timer, Every Monday, 6pm to 7pm. Select add new trigger and
repeat for Wed and Fri. You can't specify exactly the minute it will
run, but it will run in the selected hour. Here is an example you can copy and try.
https://docs.google.com/spreadsheets/d/1y-YP7AckNCRZO9w_dc43ZpGbFrfZh-zBKiuC_bEiDdI/edit?usp=sharing
I would try to accomplish this by:
First, I would create a script to change the background of the desired cells using SpreadsheetApp;
Second, I would create a script using Selenium WebDriver to open the spreadsheet and execute the function;
Finally, schedule the selenium script to run at specific dates (cron);
I'm trying to set up a Google Sheet for volunteers at the local dog shelter. The idea is to have an auto-updating spreadsheet that shows at a glance which dogs really need to be walked, in two ways:
conditional formatting the rows with color based on time elapsed:
red if it's been >6 hours since their last walk,
yellow for 3-6 hours, or
green if they were walked <3 hrs ago.
auto-sorting the rows so that the dogs that have gone the longest are always at the top of the list, and when they get walked, they go to the bottom of the list.
Here's where I'm at.
Problem 1: I'm trying to calculate time elapsed by using the NOW() function (which returns the current date and time), minus the time of the last walk. The problem is that if you only enter a time, Google apparently assumes the date is 12/30/1899. So if I put in 8:00 am, and the current time based on NOW() is 4:00 pm, instead of returning 8:00 hours, it calculates the the duration as 10,000,000+ hours that have elapsed since 8:00 am on December 30, 1899 up to the current date and time. (Similar problem discussed here).
If I keep the output cells in the HH:MM format, it'll initially look OK, because it'll just return the HH:MM as 8:00, BUT I can't use that because then the conditional formatting won't work - it's still actually calculating the 10,000,000 hours since 1899. So I can't set duration values for red/green/yellow because all the output values will be slowly increasing every day we get further away from 1899, meaning I would have to reset the ranges daily.
Obviously I could work around this by always including the time and date, but the idea is to have a spreadsheet that is idiot-proof so that any volunteer can use it by just adding the time they walked the dog. It won't work if they have to input the date too.
Problem 2: Assuming I can get the above to work, how can I set it up so the table automatically sorts itself after any change (i.e. when a dog gets walked and the entry gets updated)?
Help?
Please try:
Problem 1
Green is easy, just format all your data that way with standard fill (CF will override this where applicable).
Select A1 and apply a Custom formula is of:
=and($D1<>"",timevalue(now())>$D1+6/24)
with colour Red and Range A:E
Repeat (the order of these two is important):
=and($D1<>"",timevalue(now())>$D1+3/24)
with colour Yellow and Range A:E.
Save rules and close window.
Problem 2
Create a pivot table by selecting ColumnA:E (may have to get rid of some content present low down in the sheet first) and Data > Pivot Table Report..., to Rows Add field Dog name (do not Show totals), to Values Add field Time since last walk and Summarise by:SUM. Name the sheet PT.
In say J2 of your other sheet (not PT) enter:
=query(PT!A:B, "Select * order by B desc ")
May be worth noting that without the day part there might be problems where times span midnight - if you have walkers with insomnia?!
For the autosorting, I found a script elsewhere on stackoverflow and modified it slightly for my purposes:
function onEdit(event){
var sheet = SpreadsheetApp.getActiveSheet();
if(sheet.getName()=='Sheet1'){
var editedCell = sheet.getActiveCell();
var columnToSortBy = 4;
var tableRange = "a2:f91";
if(editedCell.getColumn() == columnToSortBy){
var range = sheet.getRange(tableRange);
range.sort( { column : columnToSortBy, ascending: true } );
}
}
}