Hello, I think I’m lost in a very basic issue.
Basically in my sheet I have a couple of formulas and a script running, but when I create let’s say a new post which should use the formulas, those are not working.
I tried to copy those formulas in the entire column, but obviously Glide will add the new entry after the last row I made — see image attached.
How I can make sure the formula is replicated in a new row?
I don’t see any attached image, but I imagine the answer would be a well crafted Arrayformula.
1 Like
Hi Robert, thanks fo looking and the link.
However I’m not sure this is what I’m looking for, or if I can’t understand how to use it, as I made some tests but I can’t solve the issue.
I’ve now added the missing image to my previous post
Here’s an excellent write-up on arrayformula usage. Glide will not write data in a row that’s occupied with a formula. It looks for an empty row. When using arrayformulas, you write the formula once and it populates all rows. You just need to make sure you delete all empty rows, otherwise new data from Glide will be written to a new row at the bottom in the sheet.
Hi,
Today I will show you the script that can make copying formulas down work, when it does not work with arrayformula.
But first, let’s have some introductions about arrayformula, for those who has not used this before in Google Sheets, some equivalents in Glide and some good practices while using it. I hope it can help you in building your Glide apps as well as applying it in your normal day job.
1/ Definition Arrayformula is defined as “a range, mathematical expression using one cell range …
2 Likes
Hi @Jeff_Hager — I managed to solve for the formula, thanks! This video helped me to understand better
However, looks like I can’t use ArrayFormula with a custom script, correct? From what I understood I should have to change something on the script.
This is the script I’m using to calculate distances between two locations
function DrivingMeters(origin, destination) {
var directions = Maps.newDirectionFinder()
// .setMode(Maps.DirectionFinder.Mode.TRANSIT)
.setOrigin(origin)
.setDestination(destination)
.getDirections();
if (directions && directions.error_message) throw directions.error_message
if (directions && directions.routes && directions.routes[0] && directions.routes[0].legs && directions.routes[0].legs[0] && directions.routes[0].legs[0].distance)
return directions.routes[0].legs[0].distance.value;
return “”;
}
Hi @mrdobelina ,
I saw you managed to solve you problem. I added to your formula the case when the event is already in the past.
The formula you can put in row 2:
=if(A2=today(),“Today”,if(A2>today(),“Leaving in “&datedif(today(),A2,“d”)&” days”,“Event over”))
The formula to be put in the header in row 1:
={“Days to event”;ArrayFormula(if(A2:A="","",if(A2:A=today(),“Today”,if(A2:A>today(),“Leaving in “&datedif(today(),A2:A,“d”)&” days”,“Event over”))))}
Thank you @nathanaelb !
I was currently solving it with a game of TEMPLATE and IF & ELSE, but the formula looks easier.
Actually, if you can work your data in the Glide Data Editor rather than in GS, that would be your preferred option.
1 Like
Can you help on using ArrayFormula with a custom script? I’m not able to make it work.
With the normal function is working
While with a custom script is not working
@mrdobelina
What values are in F1:F?
F1:F is the column where I store the date of the event.
But the problem actually is not on that formula, is on the other which is
=ARRAYFORMULA(DrivingMeters(C1:C,D1:D))
C1:C is the starting point, let’s say New York
D1:D is the arrival point, let’s say Los Angeles
The custom script is:
function DrivingMeters(origin, destination) {
var directions = Maps.newDirectionFinder()
// .setMode(Maps.DirectionFinder.Mode.TRANSIT)
.setOrigin(origin)
.setDestination(destination)
.getDirections();
if (directions && directions.error_message) throw directions.error_message
if (directions && directions.routes && directions.routes[0] && directions.routes[0].legs && directions.routes[0].legs[0] && directions.routes[0].legs[0].distance)
return directions.routes[0].legs[0].distance.value;
return “”;
}
Thanks for that - do you have a screenshot sample for F1:F?
The ARRAYFORMULA you’re using is correct I believe.
It indicates something funky with the F1:F data.
For DATEDIF to work, F1:F needs to be after TODAY(), otherwise it would yield a #NUM ! error.
There you go. I solved this issue and is working as intended.
My problem is with the other formula! See down here
It just stop on the cell where the function is added, it doesn’t go all the way to the column
You can’t use Arrayformula with a custom script.
Check out the script I wrote in this post and write a custom one for your case so that it can copy to the new rows.
Hi,
Today I will show you the script that can make copying formulas down work, when it does not work with arrayformula.
But first, let’s have some introductions about arrayformula, for those who has not used this before in Google Sheets, some equivalents in Glide and some good practices while using it. I hope it can help you in building your Glide apps as well as applying it in your normal day job.
1/ Definition Arrayformula is defined as “a range, mathematical expression using one cell range …
1 Like
Actually, it acts weird and I can’t figure out what’s going on. Sometimes it is working, sometimes not. I don’t understand.
The first row doesn’t work
Now, also if I add another row it’s not working
This is the script
function fillFormula() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName(‘Destinations’);
var vals = sheet.getRange(“N2:N”).getValues();
var lr = vals.filter(String).length;
sheet.getRange(“N”+(lr)).autoFillToNeighbor(SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES);}
Can you try the other script in that thread, the one above this?
Also, when the N2 cell is showing null, the formula is still there right?
Yes, N2 still has the formula but is not showing any value.
Now I placed the other script, and it works weird. It changes values on every row I create. See below
Original and correct - notice line 7 = 42 (distance)
After the first new row - notice line 7 is now 38 and 8 is 1295
After the second new row - notice line 7 is again 42, but 8 is now 601. Line 9 is 615 and should be correct since it’s from LA to SF in Km
Can you make a copy of some rows from that sheet so I can try a script on it?