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

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))))

Related

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)))))))

ArrayFormula + Filter

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))); "-"))}

Sum of matrix values, conditional, with infinite rows and columns

I have 2 sheets: "Planning" and "Utilization" (example)
Planning: Employees assigned to projects for each week. Some projects are not fixed but need to be simulated (checkbox = true).
Utilization: Shows the utilization of each employee for each week. Only rows with:
a) no checkbox in Planning!A2:A
b) rows with checkbox checked
c) rows with project name in Planning!B2:B are to be considered.
I'd like to have a formula in Utilization!B2 that would calculate the sums for Utilization!B2:E4. With infinite rows and columns in Planning sheet.
try:
=QUERY(QUERY({Planning!A:H};
"select Col3,sum(Col5),sum(Col6),sum(Col7),sum(Col8)
where not Col1 = FALSE
and Col3 is not null
group by Col3"; 0);
"offset 1"; 0)
UPDATE:
=ARRAYFORMULA(QUERY(QUERY({Planning!A:Z};
"select Col3,"&
TEXTJOIN(","; 1; IF(Planning!E1:1="";;"sum(Col"&COLUMN(E:Z)&")"))&"
where not Col1 = FALSE
and Col3 is not null
group by Col3"; 0);
"offset 1"; 0))
FIX for 'get' error:
=ARRAYFORMULA(QUERY(QUERY({Planning!A:D\Planning!E:Z*1};
"select Col3,"&
TEXTJOIN(","; 1; IF(Planning!E1:1="";;"sum(Col"&COLUMN(E:Z)&")"))&"
where not Col1 = FALSE
and Col3 is not null
group by Col3"; 0);
"offset 1"; 0))
For infinite rows and Columns, I like to use OFFSET() so you might try this formula in A1 on a new tab.
=ARRAYFORMULA({QUERY(QUERY({Planning!A:D\N(OFFSET(Planning!E1;;;ROWS(Planning!E:E);COUNTA(Planning!E1:1)))};"select Col3, "&TEXTJOIN(",";TRUE;"SUM(Col"&SEQUENCE(COUNTA(Planning!E1:1);1;5)&")")&" where Col2 is not null group by Col3";0);"offset 1";0)})

QUERY returns 0

I have a main data sheet (Main) with several columns, the relevant ones being column A, a date (displayed as dd.mm.YYYY) and column D, a numeric value. In a second sheet, I'm using the query function to build the sum over all these numeric values for a specific month using the following expression:
=SUM(QUERY(Main!$A$1:$D$2364; "SELECT D WHERE MONTH(A) = 1"; 1))
MONTH(A) returns a number between 0 and 11 and the above expression works perfectly well for January (0) to October (9). However, as soon as I try to compare MONTH(A)
with a number > 9, the sum shows zero despite there being numerous entries in both November and December.
What I get is this:
=SUM(QUERY(...; "SELECT D WHERE MONTH(A) = 10"; 1)) equals =SUM(QUERY(...; "SELECT D WHERE MONTH(A) = 1"; 1))
and
=SUM(QUERY(...; "SELECT D WHERE MONTH(A) = '10'"; 1)) equals 0
Can anyone help me out with this one?
try:
=SUM(IFERROR(QUERY(Main!A2:D; "SELECT D WHERE MONTH(A) = 10"; 0)))
or:
=SUMPRODUCT(IFERROR(QUERY(Main!A2:D; "SELECT D WHERE MONTH(A) = 10"; 0)))
or:
=ARRAYFORMULA(SUM(IFERROR(QUERY(Main!A2:D; "SELECT D WHERE MONTH(A) = 10"; 0)*1)))

Arrayformula to distribute ramp-up cost on other projects

I'm trying to solve this with an ARRAYFORMULA, but I'm sort of stuck, so I was hoping I could get some help here. So, I have this project calculation sheet, containing multiple customers and multiple projects. We have Ramp-up costs ("ToAllocate=TRUE", per customer) we need to distribute to other projects ("Carrier=TRUE", per customer). The Ramp-up costs (Cost per hour * Hours) need to be distributed to "Carrier" projects proportional to number of project hours / total of carrier hours. I need to come up with the arrayformula so I would have the column M filled in:
https://docs.google.com/spreadsheets/d/1OsWX80jvKgQAYuHi56ULBPm43GrZrnt7bvwtH5dy-ZM/edit?usp=sharing
(columns J, K and L are helper columns so i wouldn't put everything in M column)
delete everything in J2:M range
paste this formula into J2 cell:
=ARRAYFORMULA(IF(D2:D=TRUE; {
VLOOKUP(A2:A; QUERY(A:H; "select A,sum(H) where C=TRUE group by A"; 0); 2; 0)\
F2:F/VLOOKUP(A2:A; QUERY(A:H; "select A,sum(F) where D=TRUE group by A"; 0); 2; 0)\
VLOOKUP(A2:A; QUERY(A:H; "select A,sum(H) where C=TRUE group by A"; 0); 2; 0)*
(F2:F/VLOOKUP(A2:A; QUERY(A:H; "select A,sum(F) where D=TRUE group by A"; 0); 2; 0))\
I2:I+VLOOKUP(A2:A; QUERY(A:H; "select A,sum(H) where C=TRUE group by A"; 0); 2; 0)*
(F2:F/VLOOKUP(A2:A; QUERY(A:H; "select A,sum(F) where D=TRUE group by A"; 0); 2; 0))}; ))

Resources