Google Sheets Arrayformula for maxifs [duplicate] - google-sheets

This question already has an answer here:
How to use arrayformula with formulas that do not seem to support arrayformulas?
(1 answer)
Closed 4 months ago.
G'day people,
I am a long time supporter/reader but this is my first time posting on Stackoverflow so please bear with me.
Example of the Sheet I am working in
=if(E2="",,If(maxifs($E:$E,$K:$K,K2)=E2,K2,""))
I am a little stumped on converting this maxifs formula above that I am trying to convert to an arrayformula in Google Sheets. This formula checks to ensure E2 (timestamp) is not blank and then compares then looks all over the timestamp column for a newer timestamp for a distinct identifier (Column K example: '43909Ben Johns' (a CONCAT of a reference number and a client)) to see if there is a new version of that identifier. if it cannot find it, it will populate the row with the latest in column L (where the formula is situated) with the same identifier that is in Column K on the same row. If it does find a newer version it will populate with "".
I tried setting up an arrayformula however I could see that it wouldn't work as I was trying to convert it. It calculated the first row but left all other rows (about 10,000) blank and I suspect that is because it is trying to compare data on E2 and K2 with other rows in column E and K. Below is the array formula I tried:
=arrayformula(if(E2:E="",,If(maxifs(E2:E,K2:K,K2:K)=E2:E,K2:K,"")))
Any help to untangle this would be appreciated and if you need me to explain further, please let me know.
EDIT: Added Sample of Sheet https://docs.google.com/spreadsheets/d/1k1qK2BuYOwDPCtHedg7zV72JmE3_TQYu9EBwZVogQbU/
Kind Regards,
Ben

Here is a formula for you that can be placed in header cell (L1):
={
"Valid Check (Most Recent)";
ARRAYFORMULA(IF(E2:E = "",, IF(E2:E = VLOOKUP(K2:K, SORT({K2:K, E2:E}, 2, False), 2, 0), K2:K, "")))
}

Related

Google sheets Combining Query with Today() [duplicate]

This question already has an answer here:
How to compare dates or date against today with query on google sheets?
(1 answer)
Closed 5 months ago.
I would like to use the today function in a query. Right now I have to manually change the date each morning, which is time consuming. The query is:
=QUERY(StageTracking!A:W, "SELECT C where A =date'2021-05-13'")
When I try
=QUERY(StageTracking!A:W, "SELECT C where A =today()")
I get a #VALUE error.
I know it's just a syntax thing I'm not catching but I have tried many variations on the line above.
Let me offer another (perhaps simpler) option, given what I can tell from your post info.
Add a header in the top cell of your results column and put the following formula into the second cell of that otherwise empty column:
=FILTER(StageTracking!C2:C,StageTracking!A2:A=TODAY())
ADDENDUM (after seeing the actual sheet):
This is an excellent case in point of why it is always most efficient and effective to share a link to a sheet, since your formula attempts as originally posted (and mine as posted above) would not work with your actual layout and goal.
I've added a new sheet ("Erik Help").
First, I un-merged Rows 2-8 and simply increased the height of Row 2. There was no reason to merge those rows; and merging nearly always causes issues, especially in ranges where formulas or reference ranges are involved.
Next, I deleted your original A2 formula (=QUERY(StageTracking!A1:W1000,"select C where A = '06/23/2021'",1)) and replaced it with the simple =StageTracking!C1, which accomplishes the same thing. Again, I'm not sure what led to the long formula, but it was unnecessary.
I then deleted all of your individual erroneous formulas from B2:K2 and replaced them with one formula in B2:
=FILTER(FILTER(StageTracking!E2:W,StageTracking!A2:A=TODAY()),ISODD(COLUMN(StageTracking!E1:W1)))
This formula first creates a FILTERed array of everything from E2:W where A2:A = TODAY(). Then a second FILTER is applied to bring in only the odd columns.
NOTE: currently, while the formula is working, you will see no results in E2:W because you don't have any data for TODAY in your StageTracking sheet yet. Once you add data for today's date, you will see the formula populate B2:K2. (Or, you can simply add -1 after TODAY() in the current formula if you want to see the results from "yesterday" temporarily, in order to be sure the formula is, in fact, working.)
Try this:
=QUERY(StageTracking!A1:W1000,"select C where A = '06/23/2021'",1)
or
=QUERY(StageTracking!A1:W1000,"select C where A = date '"&TEXT(TODAY(),"yyyy-mm-dd")&"'",1)
Take a few minutes to review the scalar functions supported in the QUERY() function.
https://developers.google.com/chart/interactive/docs/querylanguage#scalar_functions
You can use YEAR(), MONTH(), DAY() or NOW(). NOW() is a compete datestamp including time, so that would require more effort.

Copy a NB.SI formula into a Google Sheets sheet

I am turning to you today for help with a problem on Google Sheets.
I receive this data from a Google Sheets form: An answer (0 or 1) to 5 different questions.
I would like to calculate in column A (in green) the scores out of 5 for each row, as soon as a new row is added by the form.
I tried to use the ARRAYFORMULA() function but it does the count for all the cells in the range and not just row by row:
Do you have an idea to have a score out of 5 for each line of question and have it apply to the whole file as soon as a new line is added by the Google Form?
Thanks for your help
If you want to use COUNTIF (English correspondance for NB.SI), modify your formula to:
=ARRAYFORMULA(COUNTIF(IF(B1:F=1,ROW(B1:B)), ROW(B1:B)))
or for your regional settings:
=ARRAYFORMULA(NB.SI(IF(B1:F=1,ROW(B1:B)), ROW(B1:B)))
You can get a row-by-row sum with sumif() like this in cell A3:
=arrayformula( sumif( if(column(B3:F), row(B3:F)), row(B3:F), B3:F) )
This formula uses open-ended range references so it will create results all the way down to the end of the sheet. To limit that, use a range reference like B3:F100 instead.

ArrayFormula with Average formula in Spreadsheet [duplicate]

This question already has answers here:
ArrayFormula of Average on Infinite Truly Dynamic Range in Google Sheets
(6 answers)
Closed 5 months ago.
So, right now im working on another spreadsheet project and this time i want to know how to use Average Formula with Array formula to make them automatically dragdown each time a new data entered.
Here is the picture from my spreadsheet. So i want to average them from Column CH to Column CL using average formula with arrayformula.
Example
I've tried all 'Averageif' or 'Average' and using arrayformula but it turns out '#DIV/0'
Can you guys please help me with it? Thankyou.
It's not going to work.
Average formula works on arrays so it won't change anything when you try nest it with arrayformula. For example. If you try to average 3 values from 3 columns, you could try: arrayformula(average(CH1:Ch,CI1:CI,CL1:CL)) but it will return the same result as average(CH1:Ch,CI1:CI,CL1:CL) - an average of all values from all 3 ranges.
I suggest workaround and make average manually (sum of elements divided by it's number):
=Arrayformula( (CH1:Ch + CI1:CI +CL1:CL)/3)
these days it can be done like:
=INDEX(IFERROR(1/(1/BYROW(OFFSET(CH2,,,
MAX((INDIRECT("CH2:"&ROWS(CH:CH))<>"")*ROW(CH2:CH)), 5),
LAMBDA(x, AVERAGE(x))))))
for more variations see: https://stackoverflow.com/a/65435321/5632629

Is there a function that can create an expanding array formula that conditionally sums a column based on multiple criteria?

To start, this is my first time posting and so please let me know if I can fix my post in any way to make it easier to answer.
I am trying to create an auto-expanding array formula
I have a sheet with my investment asset mix that including amounts of shares owned of each particular stock, and a sheet that tracks when I receive dividends. My goal is to write an automatically expanding array formula that will sum up the amount of shares that own of a stock on the date a dividend is received and return that value. I have written three different formulas that all accomplish this but none of them will auto-expand as an array.
I'm sure there are a lot of solutions I've overlooked. To boil it down, I need an expanding array formula that will sum the "Shares" column of my asset mix sheet ('Asset Mix'!D2:D, or 'AssetMixShares') conditionally. The name of the stock entered in 'Dividends'!C2:C needs to match the name of the stock in 'Asset Mix'!A2:A (or the named range 'AssetMixStocks'). It then needs to check the dates in 'Asset Mix'!C2:C (or 'AssetMixDates') against the dates in 'Dividends'!A2:A and sum all share amounts where the purchase date is less than (earlier than) the Ex-Dividend Date.
I could probably write some sort of vlookup array on the "Running Total" column -- 'Asset Mix'!E:E -- that would solve the issue, but I'm hoping to eliminate that column. I feel very strongly that what I'm trying to do should be possible without the help of a running total column -- I just don't have the knowledge.
I have tried countless functions and formulas, but the four that I currently have in my example worksheet are SUM, SUMPRODUCT, DSUM, and QUERY.
Attempt 1
SUM and IF
=ArrayFormula(SUM(IF('Asset Mix'!A:A=C2,IF('Asset Mix'!C:C<A2,'Asset Mix'!D:D))))
Attempt 2
SUMPRODUCT
=({arrayformula(SUMPRODUCT(--((AssetMixStock=(indirect("C"&ROW())))*(AssetMixDate<(indirect("A"&ROW())))),AssetMixShares))})
Attempt 3
DSUM
=DSUM('Asset Mix'!A:E,"Shares",{"Date","Stock";"<"&A2,C2})
Attempt 4
QUERY
=arrayformula(query(AssetMix,"Select sum(D) where A = '"&C2:C&"' and C < date'"&(text(year(A2:A),"0000") & "-" & text(month(A2:A),"00") & "-" & text(day(A2:A),"00"))&"' label sum(D) ''",0))
These will all work, as long as I manually drag the formula down, but I want to write some sort of formula that will auto-expand to the bottom of the Dividends sheet.
I have tried to create a Dummy sheet that has both of the relevant sheets. Please let me know if you can access it -- the link is below.
https://docs.google.com/spreadsheets/d/1wlKffma0NJ0KrlWxyX_N20y62azsGpFp3enhmjzJK1Q/edit?usp=sharing
Thanks so much for getting this far and any help you can provide!
We can focus in the first formula to understand a way to make it "self-expandable". As we see it contains references to the cells A2 and C2 in "Dividends" sheet:
=ArrayFormula(SUM(IF('Asset Mix'!A:A=C2,IF('Asset Mix'!C:C<A2,'Asset Mix'!D:D))))
Every time some data appears in these columns (A and C), the formula should work. We can control the presence of the formula by onEdit trigger, if editing is manual. Consider the code:
function onEdit(e) {
var sheet = SpreadsheetApp.getActive().getActiveSheet();
if (sheet.getName() == 'Dividends') {
var row = e.range.getRow();
for (var offset = 0; offset < e.range.getHeight(); offset++) {
sheet.getRange(3, 10).copyTo(sheet.getRange(row + offset, 10));
}
}
}
It checks any modification on the sheet "Dividends" and copies required formula to the modified row(s). This way the formula is expanded for other rows in use.
Well, it's solved! I'll leave this up in case anyone else has the same question.
A kind soul explained the magic of MMULT() to me, and wrote this solution.
=ARRAYFORMULA(MMULT((C2:C=TRANSPOSE('Asset Mix'!A2:A))*(A2:A>TRANSPOSE('Asset Mix'!C2:C)),N('Asset Mix'!D2:D))

Google spreadsheet formula to resolve string as a cell

Using google spreadsheets is there a way to evaluate a cell value as the row in a lookup operation? For example rather than =D2 to grab the value of D2, I want to evaluate the value of a cell and use it as the row to lookup another cell. I've looked at the google spreadsheet formula documentation and haven't been able to find a solution.
The below pseudocode illustrates what I'm trying to do.
A B C D
1 D
2 =[B1]2 10
3 =[B1]3 9
4 =[B1]4 8
Given the value of B1 is "D" I want cells B2, B3, and B4 to resolve to 10, 9, and 8 respectively.
You might be looking for something like this:
=INDIRECT(INDEX(B$1;1;1)&ROW())
the INDEX(B$1;1;1) gets content of B1 cell (the 1;1 is obligatory parameter, since you can feed INDEX with range and means: 1st row in range;1st column in range which is D
ROW() returns current row number, be it 2, 3 etc.
& concatenates both value, so the result is processed like "D" & "2" => "D2"
INDIRECT(reference) returns reference to a cell or an area (in text form) for which to return the contents.
see https://support.google.com/drive/table/25273?hl=en
Still, depending on what is the original problem, there might be better solutions. Above one is just straightforward answer to your question.
Bearing in mind the correctness and helpfulness of PsychoFish's advice on the use of INDEX() with INDIRECT(), and on the limited usefulness of any one solution for all problems, I think the following formula will work as well in this particular case:
=INDIRECT(B$1&Row())

Resources