I have a function that creates several rows from one, but the results are not displayed correctly, i.e. the values "No" that should be displayed in the F column are displayed in the E column if there any cell is empty. How to fix it?
https://docs.google.com/spreadsheets/d/1aI0o6XL7_Z0SAS-S2GQeLYRL4y72gKGoH9INRxDJeWA/edit?usp=sharing
You just needed to add parameters 1,0 to the SPLIT clause:
=ArrayFormula(QUERY(SPLIT(flatten(A2:A10&","&B2:B10&","&C2:C10&","&split(D2:D10,", ")&","&iferror(REGEXREPLACE(F2:F10,".*(?:"&split(D2:D10,", ")&"+ - )([^,]+).*|.+","$1"),"null")&","&iferror(REGEXREPLACE(E2:E10,".*(?:"&split(D2:D10,", ")&"+ - )([^,]+).*|.+","$1"),"null")),",",1,0),"where Col4 <> 'null' and Col4 is not null"))
However, in addition to your posted problem, I see you also have a repeated item at the bottom of the list with empty final columns. So try this version to correct both problems:
=ArrayFormula(QUERY(TRIM(SPLIT(flatten(A2:A10&","&B2:B10&","&C2:C10&","&split(D2:D10,", ")&","&iferror(REGEXREPLACE(F2:F10,".*(?:"&split(D2:D10,", ")&"+ - )([^,]+).*|.+","$1"),"null")&","&iferror(REGEXREPLACE(E2:E10,".*(?:"&split(D2:D10,", ")&"+ - )([^,]+).*|.+","$1"),"null")),",",1,0)),"Select * Where Col6 Is Not Null and Col6 <> 'null'"))
(See my added sheet, "Erik Help")
This happens because of the blank nicknames in column F. Since you are only splitting a flattened values, a null will lead to your split formula to adjust and give you a result you are not expecting. As a workaround, you can add a space in your replacement text in REPLACEREGEX formula. Instead of "$1", you can use "$1 " but note that this will add space even if the nicknames are not null.
See modified formula below and screenshot of the result:
=ArrayFormula(QUERY(SPLIT(flatten(A2:A10&","&B2:B10&","&C2:C10&","&split(D2:D10,", ")&","&iferror(REGEXREPLACE(F2:F10,".*(?:"&split(D2:D10,", ")&"+ - )([^,]+).*|.+","$1 "),"null")&","&iferror(REGEXREPLACE(E2:E10,".*(?:"&split(D2:D10,", ")&"+ - )([^,]+).*|.+","$1"),"null")),","),"where Col4 <> 'null' and Col4 is not null"))
Please let me know if you are good with this workaround.
Related
I'm pretty new with ArrayFormula, have been trying but sometime the formula works, sometimes does not. What I'm trying to do is the combination of ArrayFormula, Countif for searching partial text.
As shown in the worksheet below, there are 10 subjects (column A), each subject has at least one of 4 samples (A,B,C,D) summarized as a string (column B). What I'm trying to do is to find which subject has sample A or B or C or D.
I have tried single formula for each sample, eg cell D3
=IF(COUNTIF($B3,"*"&$D$2&"*")>0,$A3,"")
it returns the correct results. However, when I try arrayformula in cell I3,
=arrayformula(IF(COUNTIF($B3:B,"*"&$D$2&"*")>0,$A3:A,""))
The answers are weird. For example: Subjects (Gamma, Zeta, Eta, Theta) who don't have the sample "A" are shown to have sample "A". And this applies to sample B,C,D too
Not sure what went wrong in here. Here is the link to the worksheet
I wouldn't use Countifs or an array formula. Use filter instead. Put this formula in cell i3.
=Filter(if(REGEXMATCH(B3:B,$D$2),A3:A,""),B3:B<>"")
try:
=INDEX(QUERY(IFERROR(TRIM(SPLIT(FLATTEN(IF(IFERROR(SPLIT(B3:B, ","))="",,
SPLIT(B3:B, ",")&"×"&A3:A)), "×"))),
"select max(Col2) where Col2 is not null group by Col2 pivot Col1"))
or use in row 2 if you want to sort it as in your example:
=INDEX(IFNA(VLOOKUP(A2:A, QUERY(IFERROR(TRIM(SPLIT(FLATTEN(
IF(IFERROR(SPLIT(B3:B, ","))="",,SPLIT(B3:B, ",")&"×"&A3:A)), "×"))),
"select Col2,max(Col2) where Col2 is not null group by Col2
pivot Col1 label Col2'Subjects'"), {2,3,4,5}, 0)))
You can accomplish all four columns of results with a single formula.
Delete all formulas from I3:L3.
Place the following formula into I3:
=ArrayFormula(IF(REGEXMATCH(B3:B,I2:L2),A3:A,))
In plain speech, this read "If anything in B3:B matches a value found in I2:L2, return A3:A in the matching columns(s) at the matching row(s); if not, return null."
Any thoughts why doesn't this work? I need the J column to be auto-populated.
It works correctly if I just stretch down the formula.
However I need it to dynamically adjust its size according to the number of elements in column G
Is that even achievable?
try:
=QUERY(H6:H, "offset 1", 0)
or in array:
=ARRAYFORMULA({G6:G, QUERY(H6:H, "offset 1", 0)})
UPDATE:
F3 cell:
=FILTER(B2:B; MOD(ROW(A2:A)-2; 4)=0)
G3 cell:
=FILTER(B2:B; MOD(ROW(A2:A)-3; 4)=0)
H3 cell:
=FILTER(B2:B; MOD(ROW(A2:A)-1; 4)=0)
I3 cell:
=FILTER(C2:C; MOD(ROW(A2:A); 4)=0)
I think that I may have something that helps you. The only weakness is that it currently uses two "helper" columns. With some on the formula, these could be removed. Here is my sample.
First, I generate more of a database structure for the data, adding the element name to each row of data, where you have blanks in column A. I also pull the "prop4" value from the second column. If your data structure for column B and C is different then what you've shown, this formula might need adjustment.
This formula does that:
FILTER(ARRAYFORMULA({
VLOOKUP(ROW(A2:A);
IF(A2:A<>"";
{ROW(A2:A)\ A2:A});
2; 1)
\
IF(LEN(B2:B);
IF(MOD(ROW(B2:B);4)=0;
C2:C;B2:B);
ISERROR(1/0))
});
LEN(B2:B))
The result looks like column K and L in this:
Then I use a query based formula on this intermediate result, giving the final result table. The formula here (found in this question) is:
=ARRAYFORMULA(REGEXREPLACE(TRIM(SPLIT(TRANSPOSE(QUERY(QUERY(
IF(L1:L<>""; {K1:K&"♠"\ L1:L&"~"}; );
"select max(Col2) where Col1 is not null group by Col2 pivot Col1")
;;999^99)); "♠~";1;1)); "~$"; ))
I tested this by adding an element "block" at the end of column A, and by deleting an element block in the middle of column A, both of which which worked fine.
Let us know if that is the result you want. If not, please explain exactly what you expect, given your data.
I'm busy with creating an spreadsheet where I can get the average price of holidaydeals with a specific tag (f.e. a destination). When I do this for only one tag column the formula is working :) :
=averageifs(C4:C10,E4:E10,L1,F4:F10,"Frankrijk vakantie")
But... I have more then 10 tag columns in total and in every column something like "Frankrijk vakantie" could be found. My simple mind thought, okay lets change F4:F10 (in this example) to F4:G10 to look for "Frankrijk vakantie" in two columns. But... the formula didn't work.
Link to spreadsheet: https://drive.google.com/file/d/1Gw5VC5qT1bzbFIPBu5j4dLXBmJjh7GuW/view?usp=sharing
I've also added a screenshot. I hope that someone can help me with this. Would be great, thank you!
In L2 try
=query({C4:C11, ArrayFormula(N(mmult(N(F4:O11="Frankrijk vakantie"), transpose(column(F3:O3)^0))>0))}, "Select AVG(Col1) where Col2 > 0 label AVG(Col1) '' ")
and see if that works?
EDIT: to include a month/year filter try
=query({C4:C11, ArrayFormula(N(mmult(N( (F4:O11="Frankrijk vakantie")*(E4:E11=L1)), transpose(column(F3:O3)^0))>0))}, "Select AVG(Col1) where Col2 > 0 label AVG(Col1) '' ")
The formula makes use of a virtual array, containing the values of column C and the output of the mmult() function. The latter creates a column with 1's if 'Franrkijk vakantie' is found in that row AND the date in column E matches the date in L1. The query then averages the values from column C and filters out the rows where the conditions of the MMULT() are not met.
EDIT 2: To check for a 'double match' in the row, try
=query({C4:E11, transpose(query(transpose(F4:S11),,9^99))}, "Select AVG(Col1) where Col3='"&L1&"' and Col4 contains 'Frankrijk vakantie' and Col4 contains 'Europa vakantie' label AVG(Col1)''", 0)
Change range to suit.
I have two sheets. I'm using SUMPRODUCT to sum a column based on a matching string.
=SUMPRODUCT(--(skus_campaign!A:A=A2),skus_campaign!D:D)))
This works exactly as expected, if I drag the formula to the rows below.
If I attach ARRAYFORMULA and and IF test to see if there's a blank value, it won't work.
=ARRAYFORMULA(IF(ISBLANK(A2:A), " ", SUMPRODUCT(--(skus_campaign!A:A=A2),skus_campaign!D:D)))
Am I missing something here? Is there an easier way to accomplish this while still using ARRAYFORMULA to grow and shrink the column based on the values in column A?
EDIT: Here's the link to the example Google Sheet. Column "D" under the "Data" sheet is the issue.
Try in E1
={"COGS"; ArrayFormula(if(len(A2:A), vlookup(A2:A, query(skus!A:D, "Select A, sum(D) where A <>'' group by A"), 2, 0),))}
and see if that produces the desired result. If it does, clear all values and formulas in column D and enter the formula in D1.
question about GoogleSpreadsheets.
Arrayformula({Sheet1,Sheet2})
this formula works for me cause it MERGES the content of the two sheets into a 3rd sheet (both sheets and destination sheet have the same structure/columnsCount)
BUT my problem is :
- everything taken from Sheet1 is put on columns A to W (the formula is indeed in cell A1)
- everything from Sheet2 is put in columns X to AT !
Is there a way to display first all the content of Sheet1 and THEN right-under it add all the lines from Sheet2
To 'stack' vertically, you need to use a semi-colon
=Arrayformula({Sheet1; Sheet2})
Note that his will also import blank rows. So to filter those out you may need to wrap a query() around it.
=QUERY (Arrayformula({Sheet1; Sheet2}), "where Col1 <> '' ")
or if the first col is numerical
=QUERY (Arrayformula({Sheet1; Sheet2}), "where Col1 is not null ")