Google Sheets Array Formula Match on Multiple Conditions, 1 being date that is less than or equal to - google-sheets

I am hoping someone can help me out.
I have 2 different datasets and I am hoping to replicate something like the maxifs function using an arrayformula so that I only need 1 formula and do not need to drag it down.
What I would like to do is return a value that matches a name, and the date is less than or equal to a date in the column. Basically the most recent value that matches those criteria.
I have added a picture below
DEMO FIXED
The maxifs formula I am trying to replicate in this case is: =maxifs(I:I, A:A, G:G, H:H, "<=" & B:B)
Sample Sheet: https://docs.google.com/spreadsheets/d/1mMMT1JbBMTAM0togUFQtctpY5FKzgVaP2_YKnALoHAE/edit?usp=sharing
Thank you in advance.
UPDATE:
I have this formula
=arrayformula(if(len(A2:A), vlookup(A2:A&B2:B, {H2:H&I2:I, J2:J}, 2, false),))
Which almost does what I want, however if there is no date matching i need the value from the next most recent date. Instead this returns an error.

Your new goal has nothing to do with your post. Your image values don't match your sheet, and you don't want a max or equivalent to MAXIFS at all now. So the entire post will be confusing to other contributors and future site visitors. Consider spending adequate time to rework your post question, image and spreadsheet to accurately reflect your new goal in a unified way.
That said, I've added a new sheet ("Erik Help") with a formula highlighted in green which accomplished your new goal as I understand it:
=ArrayFormula(IF(A2:A="",,VLOOKUP(A2:A&"~"&B2:B,SORT({G2:G&"~"&H2:H,I2:I},1,1),2,TRUE)))
ADDENDUM (based on additional comment from OP):
I've modified the formula as follows:
=ArrayFormula(IF(A2:A="",,IFERROR(IF(REGEXEXTRACT(VLOOKUP(A2:A&"~"&B2:B,SORT(G2:G&"~"&H2:H),1,TRUE),"(.+)~")<>A2:A,"no match",VLOOKUP(A2:A&"~"&B2:B,SORT({G2:G&"~"&H2:H,I2:I},1,1),2,TRUE)))))

Related

How do I do a SUMPRODUCT in Google Sheets, but conditional on the text in both vectors?

The following spreadsheet shows the exercise submission status for 4 students. There are 4 exercises (1-4), but only 2 of them are homework (and thus graded) - they have a prefix 'H' in their name. A correct submission is marked "complete".
I'm trying to count, for each student, how many "complete" submissions he has, which are also homework. The right-most column is my desired result.
I tried all kinds of countifs, but couldn't get it. I have an ugly solution which uses SUMPRODUCT, but that requires substituting all the "complete" with 1's (which I'd rather not) + some more. I prefer a Google Sheets solution, but excel would work as well...
Have a heart and help out a teacher :-)
I suggest using mmult, which is a standard way of getting row totals from a matrix. As you mention, the first step is to convert each cell containing "complete" into a 1, then check the headers for presence of letter H.
=ArrayFormula(mmult((A2:D6="complete")*(isnumber(SEARCH("h",A1:D1))),transpose(column(A2:D6))^0))
I have tested this in Google Sheets, but it should work in Excel as well.
EDIT
(1) The easiest way to make the range accommodate changes is to put some upper limit on number of columns and make the references full-column, e.g.
=ArrayFormula(if(A2:A="","",mmult((A2:M="complete")*(isnumber(SEARCH("h",A1:M1))),transpose(column(A2:M))^0)))
You might want to move the total off onto another sheet:
=ArrayFormula(if(Sheet7!A2:A="","",mmult((Sheet7!A2:Z="complete")*(isnumber(SEARCH("h",Sheet7!A1:Z1))),transpose(column(Sheet7!A2:Z))^0)))
(2) To get the values as percentages, you can use countif:
=ArrayFormula(if(Sheet7!A2:A="","",mmult((Sheet7!A2:Z="complete")*(isnumber(SEARCH("h",Sheet7!A1:Z1))),transpose(column(Sheet7!A2:Z))^0)/countif(Sheet7!A1:Z1,"*h*")))
and format column as percent.
EDIT 2
To check for presence of H in headers but ignore h, use Find instead of Search, and regexmatch instead of countif:
=ArrayFormula(if(Sheet7!A2:A="","",mmult((Sheet7!A2:Z="complete")*(isnumber(find("H",Sheet7!A1:Z1))),transpose(column(Sheet7!A2:Z))^0)/sum(--regexmatch(""&Sheet7!A1:Z1,"H"))))
If you only want to include headers _starting_with H, change "H" in the regexmatch to "^H" as in #player0's answer.
if position of H columns is known, you can do simple:
=INDEX(IF(A2:A="",,ADD(D2:D="complete", E2:E="complete")))
if the number of columns and position of H's is unknown:
=INDEX(MMULT((INDIRECT("A2:"&ADDRESS(COUNTA($A:$A), COLUMN()-1))="complete")
*(REGEXMATCH(UPPER(INDIRECT("A1:"&ADDRESS(1, COLUMN()-1))), "^H.*")),
ROW(INDIRECT("A1:"&COLUMN()-1))^0))
update:
=INDEX(TEXT(MMULT((INDIRECT("A2:"&ADDRESS(COUNTA($A:$A), COLUMN()-1))="complete")
*(REGEXMATCH(UPPER(INDIRECT("A1:"&ADDRESS(1, COLUMN()-1))), "^H.*")),
ROW(INDIRECT("A1:"&COLUMN()-1))^0)/
SUM(1*REGEXMATCH(UPPER(INDIRECT("A1:"&ADDRESS(1, COLUMN()-1))), "^H.*")), "0.00%"))

Using =GetPivotData in GoogleSheet to get specific Grand Total

I'm trying to use =GetPivotData formula to dynamically pull specific sum totals (40% & 80% Sell-Out Probability in my example) into a table. I may not fully understand how to use the formula, but everything I've tried has returned an error.
Sample Sheet
This formula seems to pull the answer you want, if I understand your question.
=GETPIVOTDATA("SUM of Sales",H2,"Sell-Out Probability","40%")
This would go in N8 of your sample sheet.
N9 would have the same formula, but with "80%" as the last value.
Let me know if this helps.

COUNTIF Formula moves down when row at top added

I have the following COUNTIF Formula in my Google Sheet.
=COUNTIFS('Events/Incidents'!$E$3:$E,X4,'Events/Incidents'!$I$3:$I,"Accident")
This is a sample of the sheet which has the formula in the first row under the "Accidents" header:
It works until a user adds a row 3 to the top of the source sheet (Events/Incidents) then the formula changes to the following so that it captures row 4 down instead of the desired row 3.
=COUNTIFS('Events/Incidents'!$E$4:$E,X4,'Events/Incidents'!$I$4:$I,"Accident")
I used the Query function for "All Events" (the first 3 columns). The Countif formula is under each of the Incidents. In my Countif example, X4 is the Employee, John White which was returned in the QUERY.
The QUERY continues to return/include row 3 but I don't know how to do this for the individual Incidents. I tried adding ArrayFormula to the Countif function but I have the same problem.
Would appreciate some help with this.
I understand that you want to update your QUERY to reflect the correct row without resorting to returning the Branch in every response. If my comprehension is correct, there is a way to reach your goals with little modification.
First, you'll have to create a named range that includes the whole table (from the headers to the last row). You can then use this named range in every formula so new rows can be detected without changing the formula per se.
Finally, you can modify your QUERY to return only the values of Incidents in a Branch with something similar to =QUERY(myNamedRange,"SELECT G WHERE A = 'Auckland'"). That QUERY won't return the Branch, only the Incidents. If you keep having any doubts, please ask me for further help.
I worked it out by combining Countifs with ImportRange:
=COUNTIFS(IMPORTRANGE("1-f6OU8ylDSlpqdpt4P5B7GDcIel3IboVkUbY2huMA6U","Events/Incidents!$E$3:$E"),X4,IMPORTRANGE("1-f6OU8ylDSlpqdpt4P5B7GDcIel3IboVkUbY2huMA6U","Events/Incidents!$I$3:$I"),"Accident")

google sheet data filter for last a few days

I have a google sheet to log what I do at work every day.
for example
no filter
I managed to figure out how to filter it by today.
highlight colon -> data -> filter -> date is today
for example:
only today
but I could not figure out how to filter it by the last x number of days
for example:
goal
I guess I will need to make a custom filter, but I have a really hard time figuring out how to make custom filters in google sheet.
Please help me. Thanks in advance.
I solved this in two ways. One with a filter view, and one with a formula you could also use. Both are in my example spreadsheet based on your provided data.
Filter View:
To view my example use the above link and go to the sheet "Filtered". Then apply "Filter recent days" which is a filter I created. I created this filter by filtering column A for the condition "Date is after". I then chose "exact date..." which allows formula input. The formula I used was =TODAY()-4 which simply filters the data for every instance of column A which is after 4 days ago.
Filter formula:
To accomplish this, I left the original data in columns A and B. Then in C5, I entered the formula =FILTER(A3:B,A3:A>TODAY()-4), which uses basically the same method as above. This will produce a separate output next to your original data with only the recent entries.
I also took this a step further by moving the formula down a cell, and then replacing the 4 in the formula with D2. Now you can change the number in D2 to change how many days it displays.

Transpose columns into diagonals

I feel like I'm asking something that is not possible with formulas in GSheets, but I've been amazed by the things this forum has been able to answer so I'm giving it a shot. :)
I get a report each morning that show an occupancy percentage for X days out. It can be exported as a csv file and the percentages are in a column. I have made a spreadsheet where we manually put this column in as a diagonal so it reflects the occupancy of corresponding day. I have linked to a sample of this. I have put the March 31 data from 'data' in as I would like to see it displayed on 'sheet1'.
Any way to get the data from 'data' to automatically transpose or display on sheet 1? It would also need to move down a date row (sheet1) for each date column (data) that is filled.
I hope I am explaining this clearly. Let me know if I need to clarify.
Thanks!
https://docs.google.com/spreadsheets/d/1-PQ1GXRmsXrd7u9SHBT-gZkSYE6oLKkMttndmULEomY/edit?usp=sharing
You can put this into C2 and drag across that top row.:
=ARRAYFORMULA(IFERROR(Data!$B$2:$B$29/IF((COLUMN()-1=ROW(Data!$B$2:$B$29)),1,0),""))
If you insist on a single cell array formula then this works:
=ARRAYFORMULA( {IFERROR(Data!$B$2:$B$29/IF((2=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((3=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((4=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((5=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((6=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((7=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((8=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((9=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((10=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((11=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((12=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((13=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((14=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((15=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((16=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((17=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((18=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((19=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((20=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((21=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((22=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((23=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((24=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((25=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((26=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((27=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((28=ROW(Data!$B$2:$B$29)),1,0),""),IFERROR(Data!$B$2:$B$29/IF((29=ROW(Data!$B$2:$B$29)),1,0),"")})
You must delete all cells that in the range to be filled by the array formula for it to work (C2:AD29).

Resources