How can I use the COUNTA in ArrayFormula? - google-sheets

I've been trying to use ArrayFormula & COUNTA functions to achieve the result below:
I want the result to be like this
I want to count the number of the words in each field, and I am trying to drag formula down automatically when the sheet has new fields. I came up with this formula: =ARRAYFORMULA(COUNTA(transpose(split(join(char(10),$A2),char(10)))))
But when I add in new fields, the automation doesn't work. I also try to replace $A2 with $A2:A but I still couldn't automate it.
The current situation
Any thoughts would be appreciated!

Here is something that may work for you if you put this in B2:
=INDEX(IF(A2:A="","",LEN(REGEXREPLACE(A2:A&CHAR(10),"\S+(\n)","1"))))

Related

Potentially complicated formula with FILTER, VLOOKUP and multiple sheets

I am looking at using a filter to pull data from one Google sheet automatically to another Google Sheet.
The problem is, some of the values in the cells contain "," which mismatch my vlookups.
I have figured out the formula I need to automatically filter this, but I can't wrap my head around how to insert it with a filter formula.
EDIT: The below formulas are on a separate sheet to Data1 & Data2 called "Filter Sheet"
Here are the two formulas I'd like to combine:
=filter('Data2'!C2:C,'Data2'!A2:A="uk")
This one cleans up the values with "," in them:
if(REGEXMATCH(A8,","),iferror(VLOOKUP(index(split(A8,",",1),1,1),'Data1'!A2:A,1,0),iferror(VLOOKUP(index(split(A8,",",1),1,2),'Data1'!A2:A,1,0),false)))
**EDIT:The formula above looks to a different sheet (Data1) to see if the "split" result matches the VLOOKUP on the current sheet. If it does not then it goes through a loop to finally find a match on Data1 Sheet.
Essentially, I want the second statement to**
How do I insert this "clean up formula" so it can work with the filter formula values?
EDIT: How can I combine the filter formula with the "if(regex etc. formula" based on the conditions set?
OR is there an easier way of doing this?
If this helps with an easier method:
The reason why I use a filter formula is because not everything in Data Sheet 1 is found in Data Sheet 2, so this smooths that process out.
Your help is greatly appreciated and thank you in advanced.
Try this formula directly
=filter(Data2!C2:C,REGEXEXTRACT(Data2!A2:A, " (uk)")="uk")

how can I write a formula that uses a cell's contents when building a range reference to the name of another sheet?

I have a large Google Sheets spreadsheet that has individual sheets for financial statements of activity for multiple years. I want to reference particular columns of those in other sheets, and I've successfully figured out how to do that with an HLOOKUP function. However, because I want to do this for multiple years, I'd like that HLOOKUP function to pick up the name of the sheet to reference from its column header. Right now, I'm hard-coding it like this—you can see the HLOOKUP range refers to cells in the "2021 Overall" sheet. The hard-coded approach works but makes adding a new year tedious. Ideally, the HLOOKUP formula would read the contents of its column header cell to determine which year it is.
As best I can tell, the solution is to use INDIRECT, but I can't figure out any way to build the formulate with INDIRECT and not get an error. For instance, this seemed like it should work. As you can see, I have 2021 in cell D4, and my INDIRECT statement is referencing that and building the rest of the range.
I've also tried using INDIRECT with an explicit CONCATENATE, with no more success.
Any ideas for how to look up that D4 cell and slide it into the HLOOKUP range?
Thank you!
Try to remove the "'"& before D4 and the ' after the Overall.
Your formula should look like this:
=IFERROR(HLOOKUP($A$2,INDIRECT(F4 &" Overall!$A$5:$X$150", Utility!$A10, FALSE)))
With Nikko's nudges in the right direction, I eventually figured out the right format. This allows the formula to work in multiple sheets and to be filled right (for more years) and down (for more classes).
=IFERROR(HLOOKUP($A$2,INDIRECT("'"D$4&" Overall'!$A$5:$X$150"), Utility!$A3, FALSE))
Note that if you try to replicate this, you may need to type the formula out from scratch—I had a problem where pasting it in didn't work. Once I'd retyped it and Google Sheets acknowledged it, it worked from then on in the spreadsheet, even when pasted from sheet to sheet.

Using ArrayFormula with CountIF and IsBlank

I have a Google Form that asks a series of Yes/No questions. I'm trying to sum the number of Yes responses in each row as a new submission is entered.
Here's what I have, that doesn't work.
=ARRAYFORMULA(if(isblank(E$2:E),"",(COUNTIF(A2:D2,"yes"))))
It works for one cell if I remove isBlank, and just do this:
=ARRAYFORMULA(COUNTIF(A2:D2,"yes"))
But then I've lost the benefit of using "isBlank" to autopopulate for new form submissions. I'm really trying to avoid doing this with hidden sheets.
In E1 try this formula
={"Count";arrayformula(if(len(A2:A), mmult(--(B2:D="Yes"), transpose(B1:D1^0)),))}
Change range to suit.
=ARRAYFORMULA((IF(A2:A<>"",MMULT(--(A2:D="yes"),ROW(A1:A4)^0),"")))

Using IMPORTRANGE, INDIRECT, and CONCATENATE together

I have a sheet that pulls numbers from several different sheets to amalgamate numbers. Each week, a new sheet is added to the source files, all with the same name. I'd like to update the amalgamated sheet by changing one cell instead of many.
When the tab is located in the same Google sheet, this is easily done with INDIRECT.
Right now, the formula in the amalgamated sheet is:
=IMPORTRANGE(M4, "Aug29!$F$2")
That formula is on each line to pull from several different sheets:
=IMPORTRANGE(M5, "Aug29!$F$2")
=IMPORTRANGE(M6, "Aug29!$F$2")
and so on.
Each week, the "Aug29" changes to the new date - "Sep5", "Sep12", etc.
What I'd like to do is use INDIRECT to pull that part of the equation in (from cell Z1) so that I don't have to update each formula.
I was thinking I could use CONCATENATE to create the "Aug29!$F$2" portion of the formula with INDIRECT:
=IMPORTRANGE(M4, CONCATENATE(INDIRECT(Z1), "!$F$2"))
The problem is, the IMPORTRANGE formula requires quotations around the range string, and I can't figure out how to add them.
Weird problem, I'm sure, but wondering if there's anyone with a solution?
Short answer
Use =IMPORTRANGE(M4, CONCATENATE(Z1, "!$F$2")) or =IMPORTRANGE(M4, Z1&"!$F$2")
Explanation
INDIRECT requires a string that represents a cell or range references, like "Z1" but it will increase unnecessarily the complexity of your formula.
If Z1 has the name of the sheet, then just concatenate it by using CONCATENATE, CONCAT or &
UNTESTED. Please try something like:
=IMPORTRANGE(M4,Z$2)
with in Z2 something like:
=Z1&"!$F$2"
In other words, I think your IMPORTRANGE does not like INDIRECT.

Google Sheet Arrayformula with multiple mathematical functions

How would I go about formatting an arrayformula for this?:
=$D10*(sum($F10:$I10))
I've tried a few different ways but none of them work. I have a bunch of rows with that formula (where of course the row number matches, so for example:
=$D10*(sum($F10:$I10))
=$D11*(sum($F11:$I11))
=$D12*(sum($F12:$I12)) etc...
I need this formula in each row but I'm trying to figure out an arrayformula so that it works when I add or subtract rows.
Thanks for your help!
UPDATE************************************************************************
I've just figured out that =arrayformula(D7:D*(F7:F+G7:G+H7:H+I7:I)) works but I might need to add and subtract columns too. Is there a way to make it work with sum()?
I believe MMULT can be a good alternative:
=ArrayFormula(if(len(D2:D), D2:D*mmult(N(F2:I),transpose(column(F2:I2)^0)),))
Change ranges to suit.
The best way to solve math problem is to split it.
You have two multipliers: D x sum(F:F)
The first task is to make ArrayFormula with D. It's simple:
=ArraFormula(D10:D1000)
And the hard part is to make ArrayFormula with sum. This part was already asked and answered here by AdamL. In your case:
=ArrayFormula(SUMIF(IF(COLUMN(F1:I1),ROW(A10:A1000)),ROW(A10:A1000),F10:I1000))
And your final formula is
=ArrayFormula(D10:D1000 *
SUMIF(IF(COLUMN(F1:I1),ROW(A10:A1000)),ROW(A10:A1000),F10:I1000))

Resources