Google Spreadsheet ArrayFormula + VLookup Transformation - google-sheets

I have the following table on Google Spreadsheet:
And would need to get the following transformation result:
I precise that for each vegetable i can have only 1 buy price, and 1 or several sell prices
I am pretty sure this can be achieved combining ArrayFormula() + Vlookup() but have not been able to find the right formula so far. Any help would be welcomed
Thanks in advance
Cheers
Yoann

try:
=INDEX(SPLIT(FLATTEN(QUERY(TRANSPOSE(QUERY(QUERY(
{A2:C, IF(B2:B="buy", CHAR(13)&C2:C, C2:C)},
"select Col1,max(Col3) where Col1 is not null group by Col1 pivot Col4"),
"offset 1", 0)),,9^9)), " "))

Related

How to sum results obtained with VLOOKUP and IMPORTRANGE in Google Sheets?

I'm currently obtaining the result with the formula below, which was nicely provided by player0, but the challenge now is to obtain not only the figure found, but a sum, since the occurrences in the "database" may be multiple.
=Arrayformula(if(A9:A="";;IFNA(vlookup(A9:A&D9:D&"Expedição"&"Costura";
{IMPORTRANGE("fileId";"Produção!F2:F")&
IMPORTRANGE("fileId-1n3nQ";"Produção!H2:H")&
IMPORTRANGE("fileId-1n3nQ";"Produção!R2:R")&
IMPORTRANGE("fileId-1n3nQ";"Produção!B2:B")\
IMPORTRANGE("fileId-1n3nQ";"Produção!N2:N")};2;0))))
I have tried including sum in many places in the formula above, but with no success.
Here's a file with dummy data.
Thanks in advance.
use:
=ARRAYFORMULA(IF(A4:A="",,IFNA(VLOOKUP(A4:A&" "&C4:C&" Expedição Costura ",
QUERY(SPLIT(FLATTEN(QUERY(TRANSPOSE(QUERY({IMPORTRANGE(
"1gh5w0czg2JuoA3i5wPu8_eOpC4Q4TXIRhmUrg53nKMU", "Data Origin!A2:R")},
"select Col6,Col8,Col18,Col2,'×',Col14 where Col14>0 label '×'''", )),,9^9)), "×"),
"select Col1,sum(Col2) where Col2>0 group by Col1"), 2, 0))))

Google Sheets: How to combine multiple rows in their own cells according to an ID?

I tried searching for this question very hard, and only managed to find one solution that sort of works. Here's the reference: how to merge rows together if duplicate id (google spreadsheet)
His question is exactly the same as mine, and the solution partially works because sometimes google sheets have an error with custom functions and the cell just get stuck on "Loading.."
I am writing this question in hopes of being able to achieve the same results, without a custom function, using sheets native formulas.
Here's another reference to something similar to what I need: How to combine rows with same ID in Google Sheets?. It is only similar because I need the combined data to be in their own cells, and not merged into one cell.
In other words, the input:
Col A(ID) Col B(values) Col C(values)
1 sample1 sample2
2 sample2 sample4
1 newsample1 newsample2
Expected output:
Col A(ID) Col B(values) Col C(values) Col D(values) Col E(values)
1 sample1 sample2 newsample1 newsample2
2 sample2 sample4
Essentially, again it is exactly the same requirements as how to merge rows together if duplicate id (google spreadsheet), but looking for a solution using google native formula rather than a custom formula if possible.
try:
=ARRAYFORMULA(SUBSTITUTE(REGEXREPLACE(SPLIT(TRIM(FLATTEN(QUERY(QUERY(SPLIT(
FLATTEN(A1:A5&"×"&ROW(B1:C5)&COLUMN(B1:C5)&"¤"&SUBSTITUTE(B1:C5, " ", "♦")), "×"),
"select max(Col2) where Col2 is not null group by Col2 pivot Col1"),,9^9))),
" ")&"", "(^.+¤)", ), "♦", " "))
fix:
=ARRAYFORMULA(SUBSTITUTE(REGEXREPLACE(SPLIT(TRIM(FLATTEN(QUERY(QUERY(SPLIT(
FLATTEN(A3:A&"×"&TEXT(ROW(B3:H), "000000")&TEXT(COLUMN(B3:H), "000000")&"¤"&
SUBSTITUTE(B3:H, " ", "♦")), "×"),
"select max(Col2) where Col2 is not null group by Col2 pivot Col1"),,9^9))),
" ")&"", "(^.+¤)", ), "♦", " "))

What formula can be used to find unique value in two data in google sheet?

I am trying to find two unique names in two data. Could you kindly advise what formula can be used? Thank you so much
https://docs.google.com/spreadsheets/d/1lkLSmrbln3ZIZSIe25A48nH6931LzQ8DnLmfI_3jsMQ/edit?usp=sharing
try:
=QUERY(QUERY(FLATTEN(A2:B),
"select Col1,count(Col1) where Col1 is not null group by Col1"),
"select Col1 where Col2 = 1")

Index-Match with Sum-Function

I have two tabs Product-Overview and Prices.
On the Prices-tab I would like to add my data and get an overview on the financials tab.
I was trying to use index-match, however if there are several values in the same month in my Prices-tab I am not sure how to sum the up?
I would like to get the following result:
Find below my minimum viable example as google sheet:
Google Sheet
Any suggestions how to do this?
delete column D and use this in D2:
=ARRAYFORMULA(IF(A2:A="";;TEXT(B2:B; "mm/yy")))
then you can do this:
=QUERY(Prices!A2:D; "select A,sum(C) where A is not null group by A pivot D")
and more advanced in O5:
=ARRAYFORMULA(IF(O1:1="";;IF(B5:B="";;
IFNA(VLOOKUP(B5:B; QUERY(Prices!A2:D;
"select A,sum(C) where A is not null group by A pivot D");
MATCH(TO_TEXT(O1:T1); QUERY(QUERY(Prices!A2:D;
"select sum(C) where A is not null group by A pivot D");
"limit 0"; 1); 0)+1; 0))*1)))
of course B5 can be:
=SORT(UNIQUE(Prices!A2:A))
then D5 can be:
=ARRAYFORMULA(IF(B5:B="";;"Product "&REGEXEXTRACT(TO_TEXT(B5:B); ".(\d+)")))
average N5 can be done like:
=ARRAYFORMULA(QUERY(TRANSPOSE(QUERY(TRANSPOSE(O5:100);
"select "&TEXTJOIN(","; 1; IF(B5:B="";;
"avg(Col"&ROW(O5:O)-ROW(O5)+1&")"))&""));
"select Col2"))
generating dates in O1 like:
=ARRAYFORMULA(ARRAY_CONSTRAIN(TRANSPOSE(UNIQUE(TEXT(ROW(INDIRECT(
DATEVALUE("1/11/2020")&":"&
DATEVALUE("1/11/2050"))); "mm/yy"))); 1; COLUMNS(O1:1)-1))
and years in O2 like:
=ARRAYFORMULA(IFNA(20&REGEXEXTRACT(O1:1; "/(\d+)")))
What you are looking for is the sumifs formula:
This will solve your problem, it is not an arrayformula, but it works if you drag it for the cells you want them to go.
=sumifs(
Prices!$C$2:$C;
Prices!$A$2:$A;$B5;
Prices!$D$2:$D;">="&if(isblank(N$1);date(year(O$1);month(O$1)-1;day(O$1));N$1);
Prices!$D$2:$D;"<="&if(isblank(O$1);date(year(N$1);month(N$1)+1;day(N$1));O$1)
)

Phrase Frequency formula for Google Sheets

I have a column of search terms and would like to find out all the two-word phrases in this column and the frequency of each of all them. Does anyone know of a formula in Google Sheets that can help me accomplish this?
=ARRAYFORMULA(IFERROR(QUERY(IF(SPLIT(A1:A, " ")>0, A1:A, ),
"select Col2,count(Col2)
where Col2 is not null
and Col3=''
group by Col2
label count(Col2)'frequency'"),
QUERY(IF(SPLIT(A1:A, " ")>0, A1:A, ),
"select Col2,count(Col2)
where Col2 is not null
group by Col2
label count(Col2)'frequency'")))
pste in C2 and drag down:
=COUNTA(FILTER(A:A, SEARCH("*"&B2&"*", A:A)))

Resources