in Google Sheet, I use this formula to unpivot a table:
=arrayformula(SPLIT(FLATTEN(IMPORTRANGE("https://docs.google.com/spreadsheets/d/";"Foglio1!A2:A999")&"|"&IMPORTRANGE("https://docs.google.com/spreadsheets/d/";"Foglio1!AQ1:BB1")&"|"&IMPORTRANGE("https://docs.google.com/spreadsheets/d/";"Foglio1!AQ2:BB999"));"|"))
The data structure is like in the screenshot: the problem is that the unpivoting create row also when (for example) Alpha in Project A is null.
How can i fix this problem, creating unpivoted rows only if the value in the cell is > 0?
Many thanks mate!
Screenshot
Wrap the formula in a query(), like this:
=query( arrayformula(...); "where Col3 is not null"; 1 )
Related
Is there a way to get the result column in the picture below?
All i want to do is text join the Col1 if the corresponding Col2 belongs to the same groups (E.G. 1,2,3....).
Reminded that I want to use arrayformula instead of dragging down the "normal" formula myself everytime.
Use this formula
Or Make a copy of this example sheet.
=ArrayFormula({"Result";
IF(A2:A="",,
BYROW(B2:B,
LAMBDA(v,JOIN(", ",FILTER(A2:A,B2:B=v)))))})
Great news for google-sheet lovers that google releases new lambda formulas. You can use BYROW() function to make it spill array. Try below formula.
=BYROW(C3:C9,LAMBDA(x,JOIN(",",FILTER(B3:B9,C3:C9=x))))
To refer entire column use FILTER() function for BYROW().
=BYROW(FILTER(C3:C,C3:C<>""),LAMBDA(x,JOIN(",",FILTER(B3:B,C3:C=x))))
Suppose my range of data from B3:C9, want to group the result according the the Column C (or Col2)
Here is the formula i googled without using the Lambda function
=ARRAYFORMULA(REGEXREPLACE(TRIM(SPLIT(FLATTEN( QUERY(QUERY({ROW(C3:C9), C3:C9&"×", B3:B9&","}, "select max(Col3) where not Col2 starts with '×' group by Col1 pivot Col2"),,7^7)), "×")), ",$", ))
Notice the 7^7 is the (length of the data)^(length of the data).
i.e. from 3 to 9, there are 7 data.
I'm trying to count the number of most frequent text in a column, I have this formula that I used before in excel...
=INDEX(E9:E18,MODE(IF((E9:E18<>"")*ISNA(MATCH(E9:E18,$B$1:$B1,0)),MATCH(E9:E18,E9:E18,0))))
This works, but when I get some repited value shows #N/A
Here is an capture from this I would like to know how can I resolve this I tried with
=INDEX(E9:E18,MODE(IF(AND(E9:E18<>"")*ISNA(MATCH(E9:E18,$B$1:$B1,0)),MATCH(E9:E18,E9:E18,0))))
But I get lost trying to put a condition like only one value = value
Some help or code that I could use?
So this is my problem
With Office 365:
=INDEX( SORTBY(UNIQUE(A1:A10), COUNTIF( A1:A10, UNIQUE(A1:A10) ),-1), 1 )
Oops - i just saw the Google sheets edit.
For most frequent:
=INDEX( SORT(UNIQUE(A1:A10), COUNTIF( A1:A10, UNIQUE(A1:A10) ),0), 1 )
For Just One Value:
=FILTER(UNIQUE(A1:A10),COUNTIF(A1:A10,UNIQUE(A1:A10))=1)
try:
=QUERY({A:A};
"select Col1,count(Col1)
where Col1 is not null
group by Col1
label count(Col1)''")
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.
Trying to understand if it is possible to apply ARRAYFORMULA to situations when QUERY is used in Google Sheets.
For example, I used QUERY for querying and aggregating a set of items, like so:
=QUERY($H$2:$I$17,"select sum(I) where H='"&A2&"' label sum(I) ''",0)
But in order to make that work across the spreadsheet, I will have to drag this formula down. There is also the ARRAYFORMULA thing, which is supposed to help with getting rid of excessive dragging, however it does not seem to work with QUERY, or am I just missing something?
A picture for a quick look:
And a shared file for the longer thinking:
https://docs.google.com/spreadsheets/d/1xOdqeESrFbrBknNYahSeF0ripA5fr2vVFQ-r--lkdA0/edit?usp=sharing
use this formula:
=QUERY(H2:I17, "select H,sum(I) where H is not null group by H label sum(I)''", 0)
and then you can do simple VLOOKUP like:
=ARRAYFORMULA(IFNA(VLOOKUP(A2:A, QUERY(H2:I17,
"select H,sum(I) where H is not null group by H label sum(I)''", 0), 2, 0)))
Here two method alternatively:
first ==>
=arrayformula(sumif(H2:H,"=" & unique(filter(H2:H,H2:H<>"")),I2:I))
second ==>
=arrayformula(
query(
filter({vlookup(H2:H,{A2:A,row(A2:A)},2,false),H2:I},H2:H<>"")
,"Select sum(Col3) group by Col1 label Sum(Col3) ''"
)
)