Pulls & Multiplying Multiple Data Points Based on Year Criteria - google-sheets

Having an issue figuring out a proper Google sheets formula that works
This is my reference sheet
=SUM(IF(AND('Online Arbitrage'!A:A = D5, 'Online Arbitrage'!M:M >=DATE(A2,1,1), 'Online Arbitrage'!M:M <=DATE(A2,12,31), 'Online Arbitrage'!N:N> 0),'Online Arbitrage'!H:H*'Online Arbitrage'!N:N))
I tried this formula in the "Taxes" worksheet and other variants with no success.
I am needing it to pull through the total purchases per supplier from the "Online Arbitrage" sheet based on the year that I have entered into A2.
In this example, I am expecting a result of $2,696.04 and it is producing a result of $0. I've tried other variations of this formula and it produced a result of around $5,700 which was also incorrect.

Try:
=sumproduct(('Online Arbitrage'!$A$4:$A=D5)*('Online Arbitrage'!$M$4:$M>=DATE(A2,1,1))*('Online Arbitrage'!$M$4:$M<=DATE(A2,12,31))*('Online Arbitrage'!$N$4:$N>0)*'Online Arbitrage'!$H$4:$H*'Online Arbitrage'!$N$4:$N)
You generally can't use AND/OR statements in arrays as they aggregate so won't give you the expected result. Instead, use * instead of AND and + instead of OR. I've also limited your ranges to avoid the header cells.

Related

SUMIFS and ARRAYFORMULA within Google Sheets

I have a google sheet with multiple tabs, one of the tabs is for holding each observation of data while another needs to combine data based on certain criteria. I am trying to use a SUMIFS within and ARRAYFORMULA to get the correct information and it will only pull "0" no matter what I try.
I have set up a test google sheet with some dummy information to show an example of what I need to do in a more complex situation.
https://docs.google.com/spreadsheets/d/1JLyEuVijQ8MvfOKrtbRD_YKmRDnTCxf7qCSw9Ggty_Y/edit#gid=1250575550
In this example, the data tab is the individual observations and the sums tab is where I'm trying to pull combinations. I need column D to sum the totals in column E on the data tab if the Month and Year and Type all match what is on the sums sheet. In this example, cell D3 on the sums tab should equal 11.
you cannot use SUMIFS() in Arrayformula(), along with many other functions, though there is no formal documented list.
In your case you can use a SUMIF() instead by &'ing the condtions together.
I've demoed the concept on a new tab called MK_Help in cell D2:
=ARRAYFORMULA(IF(ROW(A2:A) = ROW(A2), "# TOTAL TYPE", IF(A2:A = "", , SUMIF(data!A:A&data!B:B&data!C:C,A2:A&B2:B&C2:C,data!E:E))))
Note that I made a couple of other small changes to your formula.
Namely, that you should always use a true "empty" instead of double quotes in your IF() mask up front tor return empty when there's no value in A. Double quotes("") is actually not quite empty for many other things in Google sheets.
Also I modified your header conndition from ROW(A2:A)=2 to ROW(A2:A) = ROW(A2). I find that this is a more flexible condition for the header as it allows you to potentially insert/delete rows above the header without breaking things.
It seems QUERY() may be good choice. Try-
=QUERY(data!A2:E,"select A,B,C, sum(E) where A is not null group by A,B,C",1)
If you need specific month then you can add criteria to where clause like-
=QUERY(data!A2:E,"select A,B,C, sum(E) where A =5 group by A,B,C",1)

Chart of Accounts on google sheet with arrayformula

i'm trying to create "chart of accounts" for a small accounting project , to generate accounts numbers based on accounts names ,
i already tried sheet's formulas but it isn't ideal since i'm using a form to add new accounts and it will be unsorted ,
i want to convert all formulas into arrayformulas to make it dynamic but i couldn't manage to solve that without getting slower calculation time ,
here is a:
copy of my sheet
I understand that you are looking for a better formula in 'Parent' and 'Account', right?
For 'Parent' i suggest SWITCH formula that is useful for many conditions. It also provides default value when no conditions are met.
I also use array_constrain formula that limits arrayformula to filled rows only (checks whether F column has some content).
Try in L2:
=array_constrain(
ArrayFormula(switch(K2:K,
2,F2:F&"|0|00|000|0000",
3,F2:F&"|"&G2:G&"|00|000|0000",
4,F2:F&"|"&G2:G&"|0"&H2:H&"|000|0000",
5,F2:F&"|"&G2:G&"|0"&H2:H&"|00"&I2:I&"|0000",
"0|0|00|000|0000")),
Count(F2:F),1)
'Account' column is easier as there are no conditions:
Try:
=array_constrain(
ArrayFormula(
TEXT(F2:F,"0")&"|"&TEXT(G2:G,"0")&"|"&TEXT(H2:H,"00")&"|"&TEXT(I2:I,"000")&"|"&TEXT(J2:J,"0000")
),Count(F2:F),1)
Here I also limit arrayformula to unempty rows using array_constrain.

SUMIFS and/or QUERY inside ARRAYFORMULA

Google spreadsheet sample: https://docs.google.com/spreadsheets/d/1MdRjm5QmKY_vaah9c3GrvH6dDOBCQX_zvCubvN0akmk/edit?usp=sharing
Im trying to get the sum of all values for each ID. The values im trying to add up are found in the Source tab while the calculations are done in the Output. My desired values are based on 2 things: ID and Date. The Id is supposed to match and the Date is supposed to be February. I tried first just using a sumif with just matching ID and it worked using this formula: =ARRAYFORMULA(IF(A2:A="",, SUMIF(Source!A:A,A2:A,Source!B:B)))
But when I add the 2nd critera and use a sumifs function, it only outputs for the first id. Here is the sumifs formula I used: =ARRAYFORMULA(SUMIFS(Source!B2:B,Source!A2:A,A2:A,Source!C2:C,">="&DATE(2021,2,1),Source!C2:C,"<="&DATE(2021,2,28)))
I tried using query as some of the answers I found online suggested to use it but it also outputs the first data only, here is the query formula I used =ARRAYFORMULA(QUERY(Source!A2:C,"select sum(B) where A = '"&Output!A2:A&"' and C >= date '"&TEXT(DATEVALUE("2/1/2021"),"yyyy-mm-dd")&"' and C <= date '"&TEXT(DATEVALUE("2/28/2021"),"yyyy-mm-dd")&"' label sum(B) '' "))
I know this is possible by making a temporary query/filter where you only include desired dates and from there I can use SUMIF, but I will be needing to make a monthly total and making 12 of these calculated temporary filters/query would take up a lot of space since we have a lot of data so I want to avoid this option if possible. Is there a better fix to this situation?
Solved by Astrotia - =arrayformula(sumif(I3:I20&month(K3:K20), A2:A6&2, J3:J20))

Arrayformula - Adding together a dynamically generated list of ranges

I'm looking for a way to add together a dynamically generated list of ranges using (I'm guessing) an ARRAYFORMULA.
The normal way of attacking this is fine if there is a known list of ranges, the example of the results I want would work using this:
=ARRAYFORMULA( A1:A10 + B1:B10 )
In the case I'm after I want to add together ranges in multiple sheets. I don't want the users to have to manually adjust the array formula every time they add a new sheet to be calculated, and I also want to be able to add some logic to include or remove the particular sheet from the calculation, but for now I'm happy to ignore that and just focus on adding cells together.
My approach to this was to create a column with a list of names, each one matching a sheet in the document, and then using that list to dynamically build the list of ranges to add together, using INDIRECT.
.------------.
| sheet1 | <---- SheetListNamedRange
|------------|
| sheet2 |
`------------'
Here's a quick example
=ARRAYFORMULA( INDIRECT("'" & SheetListNamedRange & "'!D4:75") )
There are lots of failure modes depending on how it's done, but this particular formula only puts in the values of the first sheet and ignores any others, which I guess makes sense.
What I'm after is kind of the equivalent of i++ in a loop found in a normal coding language. Is there some way of making this work?
If I understand you correctly, you'd like to get a list generated based on different ranges across different sheets. If your case is as simple as the one you mention in the beginning of your post, the following would do the job.
={Sheet1!A1:A2; Sheet2!B1:B2}
If you want the sum of all these values, you can use SUM.
=SUM({Sheet1!A1:A2; Sheet2!B1:B2})
Please let me know if this isn't what you were looking for, so I can change the answer accordingly.
you can't refer to array of arrays in INDIRECT. you will need to INDIRECT each sheet which contains array.
=SUMPRODUCT(ARRAYFORMULA(INDIRECT(A1&"!"&"D:D")+
INDIRECT(A2&"!"&"D:D")+
INDIRECT(A3&"!"&"D:D")+
INDIRECT(A4&"!"&"D:D")))
note1: in this case result is 25 as sum of 10 + 15.
10 is sum of sheet1!D:D
and 15 is sum of sheet2!D:D
note2: there is no sheet3 and sheet4 which is equal to 0 in INDIRECT
note3: D:D of the sheet where you have the list of sheets needs to be empty

Google Sheet - Transform two columns into one column using arrayformula (more than 50,000 characters)

I'm using Google Sheets and looking for an arrayformula that able to take a list in two columns and arrange it alternately in one column. The sheet contains about 5,000 rows, each row has more than 35 characters.
I tried this:
=transpose(split(join(" ", query(transpose(B5:C),,50000)), " "))
But then I got this message:
Please take a look at the sheet here:
https://docs.google.com/spreadsheets/d/11T1Roj1trviOSiiTZS292-4l3oODid7KLi9oGz3Z66o/edit#gid=0
Assuming your 2 columns are A and B, this formula will "interlace" them:
=query(
sort(
{arrayformula({row(A1:A3)*2, A1:A3});
arrayformula({row(B1:B3)*2+1, B1:B3})}
),
"select Col2")
Explanation, unwrapping the formula from the inside:
Each value gets a unique number, based on its row number times 2 (+1 for the 2nd column)
Everything is sorted based on this number
Only the 2nd column is extracted for the result.
There is a function for this called FLATTEN().
This works perfectly as a general solution since it takes an array of any size and outputs the items in the order they appear left-right-top-down (See here).
It can be combined with TRANSPOSE() to accomplish the same thing but in the horizontal case, and if needed blank cells can be omitted with FILTER().
EDIT:
My sincere apologies, I did not read the question carefully enough. My response is incorrect.
This should work:
={B5:B12;C5:C12}
just be careful to NOT change it to
={B5:B;C5:C}
This will start an infinite loop where the spreadsheet will increase the amount of rows in the spreadsheet to allow this output column to expand, but in doing so increases the length of the 2 input columns, meaning the length of the output column increases even more, so the spreadsheet tries adding more rows, etc, etc. It'll make your sheet crash your browser or something each time you try to open it.
In Row5:
=ArrayFormula(offset(B$5,INT((row()-5)/2),iseven(row())))
Would need to be copied down however.

Resources