I try to COUNTIF(B2:Q2;">5") for each row and return the result for each row in column A but I clearly fail on using ARRAYFORMULA for this purpose.
Could you help?
In addition to Max's solution, I believe it should be possible to use COUNTIF(). See if this works
=ARRAYFORMULA(COUNTIF(IF(B2:Q>5,ROW(B2:B)), ROW(B2:B)))
Sample File
=ARRAYFORMULA(MMULT(FILTER(--(B2:Q>5),B2:B<>""),TRANSPOSE(COLUMN(B2:Q)^0)))
mmult is effective, but slow formula. I used filter to limit the number of calculations.
Edit. Here's another formula to do the same:
=ArrayFormula(LEN(SUBSTITUTE(SUBSTITUTE(TRANSPOSE(QUERY(TRANSPOSE(FILTER(--(B2:Q>5),B2:B<>"")),,100500)),"0", "")," ","")))
Looks clunky but should work faster (not tested).
Related
Been beating my head against this and can't get it. Here is the forumla:
=IF(E3=E2,F2,F2+1)
Pretty simple. All it does is look at the cell above it...if they are the same it doesn't increase the number iteration. If they are different it does. Somehow I can't figure out how to format this in order to make it an ArrayFormula. The only reason I want it to be an Arrayformula is so that rows can be added or removed and the formula would remain intact thus the spreadsheet would be easier to use.
If you need to place it in column F from F3, you may try another approach or you'll get a circular dependency:
=BYROW(E3:E,LAMBDA(each,IF(each="","",F2+sum(MAP(E3:each, LAMBDA(c,IF(c="","",IF(c=OFFSET(c,-1,),0,1))))))))
try:
=INDEX(BYROW(E2:INDEX(E:E, MAX(ROW(E:E)*(E:E<>""))),
LAMBDA(e, IF(OFFSET(e, 1, )=e, OFFSET(e,,1), OFFSET(e,,1)+1))
I am trying to use AVERAGEIFS inside ARRAYFORMULA. Looking at other questions, I have come to the conclusion that it is not possible without using QUERY function.
My intention is to average the values of a column whenever they share the same ID.
I think this question comes pretty close to what I need, but I haven't been able to replicate and adapt its solution on my own sheet.
In this sheet I show the result I expect (I got it by dragging the formula). I've also reviewed the Query Language Reference, unsuccessfully.
Thanks a lot for your time and effort.
So the formula should be
=ArrayFormula(iferror(sumif(A2:A,A2:A,B2:B)/countif(A2:A,A2:A)))
Note that if there were any text values in the points column, this would still return a result (because count would be greater than zero) - you could instead use
=ArrayFormula(if(isnumber(B2:B),(sumif(A2:A,A2:A,B2:B)/countif(A2:A,A2:A)),""))
If you had a mixture of rows with text and rows with numbers for any ID, this would return a smaller result than the avg or average formula. This is a limitation of this method. You can't put an extra condition in (that column B has to contain a number) because you would need countifs and countifs isn't array-friendly. It still seems strange that AFAIK countif and sumif are the only functions out of this family that are array-friendly while countifs, sumifs, averageif etc. are not.
you can do:
=ARRAYFORMULA(IFERROR(VLOOKUP(A2:A; QUERY(A2:B; "select A,avg(B) group by A"); 2; )))
I want to change the columns order in google sheet from this:
To this
I know I can do this manually but if I have a lot of columns it's pretty annoying.
There's a simple way to do this?
Thanks in advance!
Building on the idea proposed by Steve in the comment. This works for any arbitrary range, pasted as tested on a range of columns A to D:
=array_constrain(
transpose(sort(transpose({A:D; arrayformula(column(A:D))}), rows(A:D)+1, false)),
rows(A:D),
columns(A:D)
)
Explanation: the 1st argument does the inversion magic by inserting a row of column numbers, transposing, sorting by this row in descending order and transposing back. Then we get rid of this extra row by constraining the result to the original dimensions.
The formula works and is generic enough, but it still feels like a hack. I wonder if someone can come up with a cleaner solution.
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))
Effectively I want to give numeric scores to alphabetic grades and sum them. In Excel, putting the LOOKUP function into an array formula works:
{=SUM(LOOKUP(grades, scoringarray))}
With the VLOOKUP function this does not work (only gets the score for the first grade). Google Spreadsheets does not appear to have the LOOKUP function and VLOOKUP fails in the same way using:
=SUM(ARRAYFORMULA(VLOOKUP(grades, scoresarray, 2, 0)))
or
=ARRAYFORMULA(SUM(VLOOKUP(grades, scoresarray, 2, 0)))
Is it possible to do this (but I have the syntax wrong)? Can you suggest a method that allows having the calculation in one simple cell like this rather than hiding the lookups somewhere else and summing them afterwards?
I'm afraid I think the answer is no. From the help text on
http://docs.google.com/support/spreadsheets/bin/answer.py?answer=71291&query=arrayformula&topic=&type=
The real power of ARRAYFORMULA comes when you take the result from one of those computations and wrap it inside a formula that does take array or range arguments: SUM, MAX, MIN, CONCATENATE,
As vlookup takes a single cell to lookup (in the first argument) I don't think you can get it to work, without using a separate range of lookups.
Google Spreadsheets does not appear to have the LOOKUP function
Presumably not then but it does have now:
grades Sheet1!A2:A4
scoringarray Sheet1!A2:B4
I still can't see the formulae in your example (just values), but that is exactly what I'm trying to do in terms of the result; obviously I can already do it "by the side" and sum separately - the key for me is doing it in one cell.
I have looked at it again this morning - using the MATCH function for the lookup works in an array formula. But then the INDEX function does not. I have also tried using it with OFFSET and INDIRECT without success. Finally, the CHOOSE function does not seem to accept a cell range as its list to choose from - the range degrades to a single value (the first cell in the range). It should also be noted that the CHOOSE function only accepts 30 values to choose from (according to the documentation). All very annoying. However, I do now have a working solution in one cell: using the CHOOSE function and explicitly listing the result cells one by one in the arguments like this:
=ARRAYFORMULA(SUM(CHOOSE(MATCH(D1:D8,Lookups!$A$1:$A$3,0),
Lookups!$B$1,Lookups!$B$2,Lookups!$B$3)))
Obviously this doesn't extend very well but hopefully the lookup tables are by nature quite fixed. For larger lookup tables it's a pain to type all the cells individually and some people may exceed the limit of 30 cells.
I would certainly welcome a more elegant solution!
I know this thread is quite old, but I'd been struggling with this same problem for some time. I finally came across a solution (well, Frankenstiened one together). It's only slightly more elegant, but should be able to work with large data sets without trouble.
The solution uses the following:
=ARRAYFORMULA(SUM(INDIRECT(ADDRESS(MATCH(), MATCH())))
as a surrogate for the vlookup function.
I hope this helps someone!
you can do so easily like this by hardcoding it in VR table:
=SUM(IFERROR(ARRAYFORMULA(VLOOKUP(A2:A, {{"A", 6};
{"B", 5};
{"C", 4};
{"D", 3};
{"E", 2};
{"F", 1}}, 2, 0)), ))
or you can use some side cells with rules:
=SUM(IFERROR(ARRAYFORMULA(VLOOKUP(A2:A, E2:F, 2, 0)), ))
alternatives: https://webapps.stackexchange.com/a/123741/186471