Tutorial: Arrayformula in Google Sheets, good practices & how to overcome Arrayformula restrictions with scripts

Each part of that determined whether the statement is true or false and returns a boolean value. If it’s true then return 1, false returns 0, so you can wrap it inside an arrayformula to calculate a sum.

1 Like

Maybe a stupid question. But can I do an array formula for Today() function? Need to use this for my calculation

Yes you can, what are you trying to calculate?

I’m trying to make a formula that calculates: What age (in week) the user (puppy) is right now. I automatically get the date they sign-up and during onboarding they have to enter the age (in week) at that date. So the I want to do a formula that calculates how many weeks to add to get the CURRENT age (hope this makes sense). E.g. age at onboarding (in weeks) + weeks passed since onboarding = current age (in weeks)

Hi Hebba .
I have this formula working in a project, it gets the age by years, months and days. Maybe is something like you mention (gettin de age)
think you can change it for your needs.

=datedif((H2:H),today(), "Y")&" Years "&datedif((H2:H),today(), "YM")&" months & "& datedif((H2:H),today(), "MD")&" days"
1 Like

Hi Hedda, I make an example here. The formula is in cell C1.

2 Likes

Wow, that’s so kind!

1 Like

Thank you @ThinhDinh for sharing your knowledge.

  1. In my situation the array formula is not pasting the values down (see picture). What should I change?

  2. Since this data (number of redemptions remaining) is a changing number (you start with 5 redemptions and it subtracts 1 every time a user presses on “redeem” button), how can I paste all data down AND allowing the data to change when a user takes an action in the app?

1 Like

With your point 2, you can’t overwrite an arrayformula, it will lead to error for the whole column. You should do that in the editor with math and rollup.

1 Like

Hi again, it works very well. the only problem is that it takes quite a while before this info updates in the app. E.g. I ask all new users to fill in the age and then it should automatically show certain content. However since I have this array calculation it takes a while before any content starts showing. Is there a workaround here? Thanks :pray:

As of now we don’t have a way to calculate with dates in the Editor, so I have to bring them back to the Sheets. If I have a workaround I’ll let you know.

Cool, thanks!

2 Likes

Evening. This opens up possibilities for glide users for sure! Thank you.

I have a little problem:

I’m trying to make an arrayformula that not only saves rows neatly like you help with in this tutorial, but one that also includes a calculation based on what number a cell in a row has.

I want basically to make the value in column E to be multiplied by 1.05 if the number in column F is 2,
multiplied by 1.08 if the number in column F is 3,
-=- 1.11 if the number in column F is 4,
etc.
Up to 15. And put the result in the D column. (Date, email and ID is occupying row ABC fyi).

I’ve tried and searched google around a quite while now and I find no one talking about this kind of combination.

I’m guessing this would be possible for someone more experienced than me, to combine this kind of Arrayformula that won’t cut all your 500 glide-rows in a second, with an advanced nested if/ifs or something.

Thank you for your time

This should be pretty easy with nested ifs in an array formula.

You can also do this within Glide by creating an if then column to get your multiplicative value, then a math column to do the math…unless you need the result within the sheet for some reason.

2 Likes

Hi Robin, I created a sheet for your case here.

The columns are:

  • Column A correlates to your column E.
  • Column B correlates to your column F
  • Column C calculates the multiplication value.
  • Column D is the final value based on column A, B and C.
  • Column E is one where I try to combine both C and D to lessen one step.

If you want this in the Editor, you can try my combined formula in a math column.

Column E * (1.05 + 0.03 * (Column F - 2))
2 Likes

Thanks for that Jeff, I ended up using Glide’s built in options as you pointed out was possible, so I could bypass using the sheet skills offered by @ThinhDinh, which I anyway learned a bunch from for the future.
Thanks guys much appreciated

2 Likes

Yeah, he’s definitely a good resource to have around here. :muscle:

3 Likes

Hi again, this have been working great however getting an error now if the the user signed up today. Is there a way to work around this?

Can you copy the formula out here for me? I cleared that sheet like a week ago and just want to make sure I will work on what I provided you. Thank you.

1 Like

Of course, thank you! :pray: =ArrayFormula({“Age now (weeks)”;ARRAYFORMULA(OM(G2:G<>"",G2:G+ROUND(DATEDIF(H2:H,TODAY(),“D”)/7,0),""))})