ArrayFormula + Filter - google-sheets

I'm creating a formula to filter 3 variables, so look for row X column 1 in this result.
So far so good.
But when I'm implementing this in arrayformula it's not working with Filter+ArrayFormula
={"Ped",
ARRAYFORMULA(IFERROR(IFS(
$A$2:$A="","",
$L$2:$L="🚫","-",
$A$2:$A<>"",INDEX(ARRAYFORMULA(FILTER(Mensagens!$A:$D,TRIM(Mensagens!$B:$B)=$E$2:$E,TRIM(Mensagens!$D:$D)=$G$2:$G,TRIM(Mensagens!$C:$C)=$I$2:$I)),$F$2:$F,1)
),"-"))}

try:
={"Ped"; ARRAYFORMULA(IFERROR(
IF(A2:A="";;
IF(L2:L="🚫"; "-";
FILTER(Mensagens!A:A;
REGEXMATCH(E2:E; TEXTJOIN("|"; 1; TRIM(Mensagens!B:B)));
REGEXMATCH(G2:G; TEXTJOIN("|"; 1; TRIM(Mensagens!D:D)));
REGEXMATCH(I2:I; TEXTJOIN("|"; 1; TRIM(Mensagens!C:C)))); )); "-"))}
update:
={"Ped"; ARRAYFORMULA(IFERROR(
IF(A2:A="";;
IF(M2:M="🚫"; "-"; VLOOKUP(F2:F&H2:H&J2:J;
{TRIM(Mensagens!B:B)&TRIM(Mensagens!D:D)&TRIM(Mensagens!C:C)\
Mensagens!A:A}; 2; 0))); "-"))}

Related

array formula to auto increment if conditions

Need array formula to auto increment column A when date is set and amount is not equal to 0
sheet link
Use scan(), like this:
=arrayformula(
if(
len(B2:B) * (to_text(C2:C) <> "0");
scan(
""; isdate_strict(B2:B) * (to_text(C2:C) <> "0");
lambda(
result; increment;
result + increment
)
);
iferror(1/0)
)
)
Here's one way you could do that:
=ArrayFormula(IF(B2:B*(C2:C&""<>"0");SCAN(;ROW(B2:C)-1;LAMBDA(a;c;a+IF(INDEX(B2:B;c)*INDEX(C2:C&""<>"0";c);1)));))
another approach:
=LAMBDA(y,MAP(INDEX(y,,1),INDEX(y,,2),LAMBDA(r,c,IF(r=0,,c))))(LAMBDA(z,{z,SCAN(,z,LAMBDA(ac,cv,ac+cv))})(INDEX(ISDATE_STRICT(B2:B)*(C2:C&""<>"0"))))

How to find the 2nd most frequently occurring text value in the dataset (without SQL query)

I have a question and need your help. Thanks in advance.
I can find the 2nd most frequently occurring text value via using SQL Query but I need to find it without SQL. (based on some conditions) / Answer 2 (new) sheet
Here is the Test Sheet
https://docs.google.com/spreadsheets/d/14aW9OMWh6AbS0Y05LKEg9L6P2uT9elxD/edit#gid=2144114460
PS: You can Edit the sheets.
=MIN('Answer 1'!$F$2:$F$15)
equals to 20 and only Hans got that
what you need is:
=INDEX(IFNA(VLOOKUP(A2:A5;
SORT({'Answer 1'!B2:B15\ 'Answer 1'!A2:A15\ 'Answer 1'!F2:F15}; 3; 1); {2\ 3}; 0)))
and try:
=INDEX(LAMBDA(y; FILTER(y; COUNTIFS(INDEX(y;;1); INDEX(y;;1);
SEQUENCE(COUNTA(INDEX(y;;1))); "<="&SEQUENCE(COUNTA(INDEX(y;;1))))=2))
(SORT(SPLIT(FLATTEN(LAMBDA(x; INDEX(QUERY(x; "select Col2,Col3,Col4"; 1); 1)&"×"&
INDEX(x;;1)&"×"&QUERY(x; "select Col2,Col3,Col4"; ))
(QUERY({'Raw Data'!B2:B\'Raw Data'!E2:E};
"select Col2,count(Col2) where not Col2 matches '^$|N/A'
group by Col2 pivot Col1"))); "×"); 1; 1; 3; 0));;2)
UPDATE - without SQL:
=BYROW(A7:A9; LAMBDA(y; TEXTJOIN(CHAR(10); 1; LAMBDA(z; FILTER(INDEX(z;;2); INDEX(z;;1)=y; INDEX(z;;3)=
LARGE(INDEX(z;;3); 2 +N("2 for 2nd largest"))))(LAMBDA(x; FILTER(x; INDEX(x;;1)=y))
(LAMBDA(b; e; SORT(SORTN(SORT({B\ E\ COUNTIFS(E; E;
SEQUENCE(COUNTA(E)); "<="&SEQUENCE(COUNTA(E)))\ B&E}; 3; 0); 9^9; 2; 4; 1); 3; 0))
(FILTER('Raw Data'!B:B; 'Raw Data'!D:D="Fail"; 'Raw Data'!E:E<>"N/A"; 'Raw Data'!B:B=y);
FILTER('Raw Data'!E:E; 'Raw Data'!D:D="Fail"; 'Raw Data'!E:E<>"N/A"; 'Raw Data'!B:B=y)))))))

Calculate sum of row but its initial row number and row count

Let's say I have a column of numbers:
1
2
3
4
5
6
7
8
Is there a formula that can calculate sum of numbers starting from n-th row and adding to the sum k numbers, for example start from 4th row and add 3 numbers down the row, i.e. PartialSum(4, 3) would be 4 + 5 + 6 = 15
BTW I can't use App Script as now it has some type of error Error code RESOURCE_EXHAUSTED. and in general I have had issue of stabile work with App Script before too.
As Tanaike mentioned, the error code when using Google Apps Script was just a temporary bug that seems to be solved at this moment.
Now, I can think of 2 possible solutions for this using custom functions:
Solution 1
If your data follows a specific numeric order one by one just like the example provided in the post, you may want to consider using the following code:
function PartialSum(n, k) {
let sum = n;
for(let i=1; i<k; i++)
{
sum = sum + n + i;
}
return sum;
}
Solution 2
If your data does not follow any particular order and you just want to sum a specific number of rows that follow the row you select, then you can use:
function PartialSum(n, k) {
let ss = SpreadsheetApp.getActiveSheet();
let r = ss.getRange(n, 1); // Set column 1 as default (change it as needed)
let sum = n;
for(let i=1; i<k; i++)
{
let val = ss.getRange(n + i, 1).getValue();
sum = sum + val;
}
return sum;
}
Result:
References:
Custom Functions in Google Sheets
Formula:
= SUM( OFFSEET( initialCellName, 0, 0, numberOfElementsInColumn, 0) )
Example add 7 elements starting from A5 cell:
= SUM( OFFSEET( A5, 0, 0, 7, 0) )

IF ELSE statement returning a syntax error

I am trying to make formula for column value autofilling for blank rows in Google Sheets.
=IF(NOT(ISBLANK(B2)); B2; IF(E2=“male”; 0; IF(AND(D2=3; J2>20); 0; 1)))
and getting syntax error.
use " not “ ”:
=IF(NOT(ISBLANK(B2)); B2; IF(E2="male"; 0; IF(AND(D2=3; J2>20); 0; 1)))
if you intend to drag it down try this in row 2:
=ARRAYFORMULA(IF(NOT(ISBLANK(B2:B)); B2:B;
IF(E2:E="male"; 0; IF((D2:D=3)*(J2:J>20); 0; 1))))

Why Index + Match + Maxifs not working for weekends (day name)

I'm using the formula below to get the qty of the last day matching the weekday name and the product code.
It works fine for weekdays, but on the weekend days, it brings only the first occurrence, repeating it down the rows, despite the product code criteria changes.
=arrayformula(INDEX('Inventory'!$B$7:$M;(MATCH(MAXIFS('Inventory'!$B$7:$B;'Inventory'!$M$7:$M;L$6;'Inventory'!$D$7:$D;$C7);'Inventory'!$B$7:$B;0));7))
Here's the table it brings values from:
|N |Date |Resp|Cód. Produto|Descrição Produto|Lote|Unid.|Qtd.|PreçoUnit|Total|Data de Validade|Local|Weekday
Could anyone point out where the flaw sits in this case?
Thank you!
use in L7:
=ARRAYFORMULA(IFNA(VLOOKUP($C$7:$C; SORTN(QUERY(SORT(
{'Entrada - Estoque'!$B$7:$B\ 'Entrada - Estoque'!$D$7:$D\ 'Entrada - Estoque'!$H$7:$H\ TEXT('Entrada - Estoque'!$B$7:$B; "ddd")}; 1; 0; 2; 1);
"select Col2,Col3 where Col4 = '"&L6&"' and Col3 is not null"); 9^9; 2; 1; 1); 2; 0)/SUM(INDEX(SORTN(QUERY(SORT(
{'Entrada - Estoque'!$B$7:$B\ 'Entrada - Estoque'!$D$7:$D\ 'Entrada - Estoque'!$H$7:$H\ TEXT('Entrada - Estoque'!$B$7:$B; "ddd")}; 1; 0; 2; 1);
"select Col2,Col3 where Col4 = '"&L6&"' and Col3 is not null"); 9^9; 2; 1; 1);;2))))

Resources