How to combine Arrayconstrain and Vlookup formula in google sheet? - google-sheets

I created a slip format in Google Sheets and I would also print it afterwards.
These slips are numbered from 1 to infinity.
I need help in constructing the formula.
What i created so far:
https://docs.google.com/spreadsheets/d/1MU_kBQgfyqgFuVet3hU6DW_WLuYwYYJ51uU-cB38gsQ/edit?usp=sharing
What i wanted to happen:
When I type the number in cell S1, it would also reflect the corresponding QWS No. in cell T2.
To do this, I was thinking that I should incorporate Vlookup (as what i placed in cell S2) inside the Arrayconstrain formula in column T. However, I don't know if it is possible though.

Answer:
Rather than using VLOOKUP, you can do this by running a QUERY instead.
Forumla:
=ARRAY_CONSTRAIN(QUERY('QWS Tracker'!A3:B, "select B where (A="&S1&") or (A="&S1+1&") or (A="&S1+2&")"),3,1)
Rundown of this Formula:
Query the sheet 'QWS Tracker'!A3:B for:
Values of column B where:
The corresponding cell in row A is either S1, S1 + 1 or S1 + 2
Contstrain the Array to length 3
References:
ARRAY_CONSTRAIN - Docs Editors Help
QUERY - Docs Editors Help
Query Language Reference (Version 0.7) | Charts | Google Developers

Related

Google sheets return Values only if exists

I have this Google sheets
In column K, I only want to return values if they are pre-existing in Column E,F, Etc..
How can I do this knowing that I will add months 2023-02, 2023-3, etc?
Here's my example:
https://docs.google.com/spreadsheets/d/1FMBkmMKJuIn0qtxDzvaWG2x5IpcR92X4-G9b8DUd9Z4/edit#gid=0
You could use an array formula.
In I4 you can put
=ArrayFormula(IF(LEN(C$3:F$3), H4:L4+C4:F4/$C$1, ""))
and drag down
And enable iterative calculation as the formula depends on its earlier results (ok to limit to 1 iteration I think)

ARRAYFORMULA is only populating the first row

I have financial data that I am trying to summarize in a format that can be used by a line chart.
The example spreadsheet is here.
In my source data on the left, I have an entry per Date, Symbol, Account. I need to transform this data so there is a row per Date and a column for each Symbol. I will SUM Total Value regardless of account.
I found a way to pull a unique Date (see H2), and then transpose unique Symbols into columns (see I1).
I also found a way to use SUMIFS to get the aggregation I want (take a look at cell I2), but I can't figure out how to use ARRAYFORMULA to apply this value to all rows in column I.
I know I can drag my formula from I2 down to I3,I4,I.. etc, but this sheet is part of a larger project so I'd like it to auto-populate as dates are added to H.
From what I've read ARRAYFORMULA should apply the formula to multiple rows. What am I missing?
Thanks
use:
=QUERY(A1:F, "select A,sum(F) where A is not null group by A pivot B", 1)
Use formulas like this
=ARRAYFORMULA(IF(H2:H="",,SUMIFS($F$2:$F, $A$2:$A, $H2, $B$2:$B, I$1)))
Add IF(H2:H="",,
Explanation
if the range is empty "" do nothing ,, else Your formula
Your Example
Cells
Formulas
I2
=ARRAYFORMULA(IF(H2:H="",,SUMIFS($F$2:$F, $A$2:$A, $H2:H, $B$2:$B, I$1)))
J2
=ARRAYFORMULA(IF(H2:H="",,SUMIFS($F$2:$F, $A$2:$A, $H2:H, $B$2:$B, J$1)))
K2
=ARRAYFORMULA(IF(H2:H="",,SUMIFS($F$2:$F, $A$2:$A, $H2:H, $B$2:$B, K$1)))

Sum every n columns starting at the 1st column in the range

In Excel/Google Sheets I have found how to sum every N columns on websites such as https://exceljet.net/formula/fixed-value-every-n-columns, but the problem is, from what I can see is that it starts at N column each time. I need something that starts from column 1 and then counts every N columns. like the following:
I need to do this with a formula and not a script.
With Google-Sheets, try:
Formula in M2:
=SUM(QUERY(TRANSPOSE(A2:J2),"Skipping "&L2))
Or, a single dynamic array formula (without dragging):
=INDEX(MMULT(A2:J4*(MOD(COLUMN(A2:J4),L2:L4)=1),SEQUENCE(10,1,1,0)))
Or, more dynamic:
=INDEX(MMULT(A2:J4*(MOD(COLUMN(A2:J4),L2:L4)=1),SEQUENCE(COLUMNS(A2:J4),1,1,0)))
Note: The latter would also work in Excel with slight modifications.
Google sheets formula:
=SUM(FILTER(A2:J2, MOD(A2:J2, L2)=1))
then drag to other cells
or use this array version:
Array version:
=INDEX(TRANSPOSE(MMULT(A2:J4,TRANSPOSE(COLUMN(A2:J4)^0 *
N(MOD(COLUMN(A2:J4), L2:L4)=1)))), ,1)
If you want the cells that were added to be automatically highlighted.
Conditional formatting used on A2:J:
=MOD(COLUMN(), $L2)=1
In M2:
=SUMPRODUCT(A2:J2,N(MOD(SEQUENCE(,COLUMNS(A2:J2),0),L2)=0))
and copied down.
Try this formula on column M:
=SUM((sumif(ArrayFormula(mod((COLUMN(B2:J2)-COLUMN(B2)+1),L2)),0,B2:J2))+A2)
Here's the result on Column M.
Just to break down the code sumif(ArrayFormula(mod((COLUMN(B2:J2)-COLUMN(B2)+1),L2)),0,B2:J2) does the actual calculation with the number of intervals set on Column L but take note that I started at the 2nd column so the range here does not include the first column. The result from this is at the Column O highlighted red as you can see in the screenshot.
At the Column M is the actual solution where I only added the first column by using SUM on top of the previous formula.
I hope my explanation is clear.
Just copy/drag the formula down to each row and it should work.
Reference: How to Sum Every Nth Row or Column in Google Sheets Using SUMIF

How to create arrayformula sequence number separated by comma in google sheets

How to create arrayformula sequence number separated by comma in google spreadsheets
expected results is in column B
A
B
5
1,2,3,4,5
2
1,2
3
1,2,3
How about the following sample formula?
Sample formula:
=JOIN(",",ARRAYFORMULA(ROW(INDIRECT("A1:A"&A1))))
When you use this formula, please put this to a cell "B1" and drag down it.
The flow of this formula is as follows.
Create a1Notation of cells using "A1:A"&A1 using INDIRECT.
Retrieve row numbers from the a1Notation using ROW.
Join the row numbers with , using JOIN.
Result:
Note:
When you want to put all result values using one formula, unfortunately, I couldn't find the formula using the built-in functions. In that case, I would like to propose to a custom function as follows. When you use this, please copy and paste the following script to the script editor of Spreadsheet.
And, please put a formula of =SAMPLE(A1:A) to a cell "B1". By this, the result values are put to the column "B" using the values of column "A".
const SAMPLE = v => v.map(([e]) => e && !isNaN(e) ? [...Array(e)].map((_, i) => i + 1).join(",") : "");
References:
INDIRECT
ROW
JOIN
Custom Functions in Google Sheets
You can use TEXTJOIN() with SEQUENCE() function.
=TEXTJOIN(",",TRUE,SEQUENCE(A1))
You can also use this functions in desktop Excel365

How to invert INDEX formula in Google sheets

I have a sheet named NYSEDB with stock names in column A and the companies that issued them in column B.
In another sheet I have companies in cells B2 and C2 (for example, AAPL, GOOGL etc.).
I have the following formula:
=ArrayFormula(IFERROR(INDEX(NYSEDB!$A:$B,SMALL(IF(NYSEDB!$B:$B={$B$2,$C$2},ROW(NYSEDB!$A:$A)),ROW(1:1)),1,1),""))
This formula, when I spread it down the sheet, returns all the stocks from NYSEDB that are issued by the companies I have specified in B2 and C2.
How can I make the exact opposite formula and "invert" the task - I want for the formula to show all stocks from NYSEDB WITHOUT those issued by the companies I have specified in B2 and C2.
Solution
Use the not equal operand <> instead of the equal one =.
In this case It's better to use the QUERY function. Which is effectively more expressive than an IF statement and makes exclusion straightforward using an array of exceptions.
Your formula will be then like:
=QUERY(NYSEDB!A:B, "select A where B<>'"&TEXTJOIN("' and B<>'", TRUE, B2:C2)&"'", -1)
Note: you can add as many exceptions as you want, but you will have to edit the B2:C2 range in the QUERY formula.
In this way the Query function will return the column A value whenever the column B value is not included in the exception row.
Reference
QUERY Formula

Resources