Sum multiple arrays into one - google-sheets

Been trying to tackle this issue for a couple days and without much progress.
I have a multiple date filter (or a query) which filters a date array: i.e. array of dates from 12.2020 to 01.2022 and multiple filters range (01.2021-02.2021, 05.2021-09.2021).
This process filters the dates and produces multiple filtered arrays. The pic of how it looks is attached.
The formula used to produce arrays =ARRAYFORMULA(IF((($F$5:$S$5>=QUERY($B$3:$D$4;"select C where B = "&D8&""))*(F$5:$S$5<=ARRAYFORMULA(FILTER($D$3:$D$4;$B$3:$B$4=$D$8))));1;0))
As you can see, it generate multiple arrays, depending on the amount of filters applied.
My question is following is it possible to sum these arrays into one with one formula? So I would get 1 array instead of multiple.
EDIT 1: Link for clarity
Screenshot of google sheet

Try
=transpose(mmult(arrayformula(VALUE(transpose( ARRAYFORMULA(IF((($F$5:$S$5>=QUERY($B$3:$D$4,"select C where B = "&D8&""))*(F$5:$S$5<=ARRAYFORMULA(FILTER($D$3:$D$4,$B$3:$B$4=$D$8)))),1,0)) ))),sequence( 2,1,1,0)))
Explanation
I encapsulate your formula and your result in a MMULT formula to get the sum of each column
=transpose(mmult(arrayformula(VALUE(transpose(F8:S9))),sequence(2,1,1,0)))

Another option:
=ARRAYFORMULA(MMULT(COLUMN($B$3:$D$5)^0,(($F$5:$S$5>=QUERY($B$3:$D$5,"select C where B = "&D8&""))*(F$5:$S$5<=ARRAYFORMULA(FILTER($D$3:$D$5,$B$3:$B$5=$D$8))))))

Related

Unnest two columns in google sheet

I have a table like this one here (basically it's data from a google form with multiple choice answers in column A and B and non-muliple choice data in column C) I need a separate row for each multiple choice answer.
Column A
Column B
Email
A,B
XX,YY
1#gmail.com
A,C
FF,DD
2#gmail.com
I tried to un-nest the first column and keep the remaining columns like this
enter image description here
I tried several approaches I found with flatten and split with array formulas but I don't know where to start really.
Any help or hint would be much appreciated!
You can use the split function on the column A and after that, use the index function. Considering the table, you can use:
=index(split(A2,","),1,1)
The split function separate the text using the delimiter indicated, returning an array with 1 line and 2 columns; the index function will return the first line and the first column from this array. To return the second element from the column A, just change to
=index(split(A2,","),1,2)
I think there's no easy solution for this. You're asking for as many combinations of elements as multiple-choice elections have been made. Any function in Google Sheets has its potentials and limitations about how many elements it can express. One very useful formula here is REDUCE. With REDUCE and sequences of elements separated by commas counted with COUNTA, you can stablish this formula:
=QUERY(REDUCE({"Col A","Col B","Email"},SEQUENCE(COUNTA(A2:A)),LAMBDA(z,c,{z;LAMBDA(ax,bx,
REDUCE({"","",""},SEQUENCE(ax),LAMBDA(w,a,
{w;
REDUCE({"","",""},SEQUENCE(bx),LAMBDA(y,b,
{y;INDEX(SPLIT(INDEX(A2:A,c),","),,a),INDEX(SPLIT(INDEX(B2:B,c),","),,b),INDEX(C2:C,c)}
))})))
(COUNTA(SPLIT(INDEX(A2:A,c),",")),COUNTA(SPLIT(INDEX(B2:B,c),",")))})),
"Where Col1 is not null",1)
Since I had to use a "initial value" in every REDUCE, I then used QUERY to filter the empty values:

Automatically fill sum column

I have a table of items with its buying and selling rates. Against each transaction, I wanted to show the item qty currently available and the current cost. Here is a screenshot of the table.
For the columns of Qty and Rate, I have used the formulas as shown below:
=SUMPRODUCT(C$2:C-F$2:F,B$2:B=B2,A$2:A<=A2)
=SUMPRODUCT(I$2:I/J2,B$2:B=B2,A$2:A<=A2)
Is it possible to convert SUMPRODUCT formulas as an array formula (returning array) so that it automatically fills whenever a row is added? Something like filling a column using FILTER or QUERY?
Regards,
Pravin Kumar.
I am making an assumption that this is your goal:
To automatically fill the quantity remaining column with the result of the difference between the two values, if and only if, there are two values provided.
A solution to this objective is:
=arrayformula(if(and(C2:C<>””, F2:F<>””), C2:C-F2:F, “”))
This produces a formula that subtracts C from F only if both C and F have values, and for all rows that have values in both C and F. If one of the rows does not have a value, the result will yield “” (blank). This formula should be posted at the top of the column where you want these results to start. In your screenshot example this would be cell J2. NOTE: 0 is still a value, and also that an array formula will not overwrite manually input data, so once you paste that function in J2, you will have to clear the cells below in order for it to auto populate.

Google Sheets Filter + Match? Not sure

I have two tabs in a sheet, that have different ranges. One is preset data, the other is an import from a program we use. I'm trying to figure out a way, if possible, to pull specific data from sheet 1, and match it with values in sheet two, that aren't sorted the same.
Example sheet
https://docs.google.com/spreadsheets/d/1OsSWQ_48VrcTU3pXGeJ_1syluKPVeVRune39UA9I3x4/edit?usp=sharing
I'm trying the formula =sort(filter(Sheet1!B1:B,match(B1:B, Sheet1!B1:B ,0)),2,TRUE), but it's just putting the results in order. If I replace the column # on the sort with 1, it sorts it out of order but it doesn't match column B, like I need it to.
The documents i'm working with are 2000+ rows each, I'd rather not manually do this if at all possible.
Please assist? Either way, thank you for reading.
Try:
=arrayformula(iferror(vlookup(MATCH( B1:B,Sheet1!$B$1:B,0),{(ROW(Sheet1!A1:A)),Sheet1!A1:A},2,0)))
Explanation
step#1 =arrayformula(MATCH( B1:B,Sheet1!$B$1:B,0)) will give the row where each value column B will be found in Sheet1!column B
step #2 =arrayformula({ROW(Sheet1!A1:A),Sheet1!A1:A}) will build a virtual matrix whith in column#1 the row and in column#2 the value of Sheet1!column A
finally: join the two formulas as vlookup(___step#1____,____step#2______)

Arrayformula is overwriting the results of the subsequent rows instead of populating their own values

The below formula is working
=query(INDIRECT(F23&"!A4:G"),"SELECT G WHERE A = '"&Overview!A23&"'")
When i convert it to Array formula like this it overwrites the results of next rows.
=query(INDIRECT(F23&"!A4:G"),"SELECT G WHERE A = '"&Overview!A23&"'")
How can we write array formula for this scenario? Note: Here we are going to different sheets and finding the value.
INDIRECT(), does not iterate within ARRAYFORMULAS. If you want to use Indirect you will have to drag it down.

In Google Sheets, how can Array elements be passed as individual arguments to a Google Sheets native function?

My question is very similar to the one described here: How can I pass an array's elements as individual arguments to a function?
The twist here is doing it inside Google sheets. In column A, there are a series of entries, from which I want to filter those that match certain criteria, and then in some other individual cells, populate the n-th result of the filter.
COL A1:A4
John A
Hector C
Mario G
Hecate J
Cell C4: =CHOOSE(1,FILTER(A1:A4, LEFT(A1:A4,1)="H"))
Cell D8: =CHOOSE(2,FILTER(A1:A4, LEFT(A1:A4,1)="H"))
But what happens is that C4:C5 are populated with Hector C and Hecate J, and D8 returns "Error Function CHOOSE parameter 1 value is 2. Valid values are between 1 and 1 inclusive."
My conclusion is that the Array that FILTER returns, is simply taken as a single argument by the CHOOSE function, instead of taking the individual elements as arguments.
I tried fiddling with the ArrayFormula, but no luck. I tried the long shot of preppending the "..." and obviously is not recognized as a function.
Any ideas that do not involve writing my own Script function?
Thanks.
You can use index() instead:
Then you can select the n-th element of the list like that:
=index(FILTER(A1:A4, LEFT(A1:A4,1)="H"),2)
Instead of having 2 as a hardcopy number you can also specify the length of the list to take for example the last element of the filtered list:
=index(FILTER(A1:A4, LEFT(A1:A4,1)="H"),COUNTA(FILTER(A1:A4, LEFT(A1:A4,1)="H")))

Resources