Google Sheets - new starting point for an array - arrays

In Google Sheets, running an array to transpose raw data into a readable format. The array forumula runs off of a row of data and am using the array to transpose the data into multiple rows. The issue is that for every additional row of raw data, I create five new rows of transposed data so the array formula breaks. Trying to make the array formula flex to added rows of data - any thought would be appreciated!
https://docs.google.com/spreadsheets/d/16GOsH-EUDm2IeRgUgEQ8LBEltQASfJ8hR6GXh-pqNcM/edit?usp=sharing

Rather than use an array formula, you can use an indirect formula and modulo arithmetic and integer division to do this. In k2 put the formula =indirect("A"&(3+FLOOR((row()-2)/5))) which will get the date from column A row 3 until you get down to row 7, when it starts taking from row 4. This formula can be dragged down and will jump rows every 5 as desired.
Similarly for L2 place in =indirect("B"&(3+FLOOR((row()-2)/5))) which can also be dragged down (copied) the column.
For column m we need to cycle through c2,d2,e2,f2, and g2, so we need modulo (clock) arithmentic. So in m2 place the formula =indirect(char(CODE("C")+(mod(ROW()-2,5)))&"2"). Finally for quantity we need to do both the column cycling and the incrementing rows every 5, so the formula for n2 is =indirect(char(CODE("C")+(mod(ROW()-2,5)))&(3+FLOOR((row()-2)/5))). That too can get copied on down. That should do it. There could definitely be more elegant ways.
I think not more elegant, but preserving the array formula would be =3+floor((row()-2)/5) in j2 and drag on down, and then adapt the array formula to: ={INDIRECT("A" & J2),INDIRECT("B"&J2),$C$2,INDIRECT("C"&J2);INDIRECT("A" & J2),INDIRECT("B"&J2),$D$2,INDIRECT("D"&J2);INDIRECT("A" & J2),INDIRECT("B"&J2),$E$2,INDIRECT("E"&J2);INDIRECT("A" & J2),INDIRECT("B"&J2),$F$2,INDIRECT("F"&J2);INDIRECT("A" & J2),INDIRECT("B"&J2),$G$2,INDIRECT("G"&J2)} which can be copied to 5 rows below it where the J2's become J7's and you are processing the next desired row.

Related

How can I drag down to multiple rows a formula which has more than 1 row in its result?

I have an extension I am getting the data from, and I am referring to that extension in a formula with result of pre determined rows but I want more than 1 row in its result and that's when I have this problem, because I want to drag the formula to multiple rows but they overlap each other, for example if I wanted 3 rows in the result of the formula starting in row 1 and then drag it down from row 1 to row 3 the formula in row 1 and 2 will show an error because they're overlapped in each other I will put a picture in how it looks...
Is there a way to specify amount of rows as a space between each formula in a way that when I drag the formula down to more rows it will adjust to the "space" I specified?
This is the formula I am using, I am also referring to another sheet as you can see so it'll be great if you can use this formula to answer my question, if I can specify the "space" using another formula that is (also it's probably obvious but the pre determined rows in the formula is the "2d").
=CRYPTOFINANCE("KRAKEN:"&'crypto-track'!C4&"/USD", "price_history", "2d")
this is usually solved by constructing an array of formulae where you stack them up in the line like:
={CRYPTOFINANCE("KRAKEN:"&'crypto-track'!C4&"/USD", "price_history", "2d");
CRYPTOFINANCE("KRAKEN:"&'crypto-track'!C5&"/USD", "price_history", "2d");
CRYPTOFINANCE("KRAKEN:"&'crypto-track'!C6&"/USD", "price_history", "2d")}
this way the 2nd fx will pick up right after 1 fx ends
you can ease your pain of a "hand job" from constructing such an array - especially if that array needs to span over the larger range - by building a formula to generate a formula. for example: https://stackoverflow.com/a/68278101/5632629
also, make sure you obey the law of array constructs and successfully avoid all array errors - https://stackoverflow.com/a/58042211/5632629

How to optimize Excel formula automatically when drag and drop?

I have an excel formula that is looking for some courses in an array from a cell. In the picture below the column A2 is populated automatically from Wix with an array of courses that can contain 1 to 10 courses. And in regard to this array, the A:K columns are populated with 1 if the course exist in the array and 0 if not.
The formula is: =--ISNUMBER(FIND(""""&B2:K2&"""",A2))
The problem is when I fill a row and drag and drop to populate the formula to a great number of rows, the formula is changing. I need to keep B2:K2 the same, and only the A2 should change . If the row is A3, in the formula I should have =--ISNUMBER(FIND(""""&B2:K2&"""",A3)).
How can I automatically do this, because I have a large numbers if rows, and cannot right the formula to all rows?
If you want to keep B2:K2 constant then lock them by $ means absolute position like-
=--ISNUMBER(FIND(""""&$B$2:$K$2&"""",A2))
You can try below formula at once for whole range of data.
=IF(ISERROR(FILTERXML("<t><s>"&SUBSTITUTE(A2:A4,",","</s><s>")&"</s></t>","//s[contains(., '" & $B$1:$K$1 & "')]")),0,1)

Sum across rows and count rows less than 0

I am trying to identify inventory shortages for each store and the type of bread I am supplying.
Example table showing the demand for each type of bread by store.
Row 8 is what I am trying to accomplish with a formula.
Based on the quantity on hand, I can conditionally format to highlight cells red or green based on shortages.
I can't get a formula to count the number of red cells.
I am thinking I need to use sumproduct.
=SUMPRODUCT(--($B9:$B11<C9:C11))
The above works for identifying shortages for Store A (Column C). However, when dragged to column D and E it doesn't remember what the other stores needed.
I can't get the rows to sum without adding ALL rows in the range. I need each row to be individually compared to the qty on hand. I assume an array needs to be used.
This is the formula I mentioned. It uses a standard method with mmult to get the row totals of the matrix, then compares them with the amounts available:
=SUM(--($B9:$B11<MMULT($C9:C11,TRANSPOSE(COLUMN($C9:C11)^0))))
entered in C8 and pulled across. Must be entered as an array formula using CtrlShiftEnter
EDIT
OP has commented that it shouldn't be listed as a shortage if a store doesn't need a particular item, even if the stock of that item has been exhausted.
So there should be an extra condition for it to be registered as a shortage only if the current column has a number >0 in a particular row as well as the row sum being greater than the amount available:
=SUM((C9:C11>0)*($B9:$B11<MMULT($C9:C11,TRANSPOSE(COLUMN($C9:C11)^0))))
If you wanted to select only some of the rows as well it would look like
=SUM(ISNUMBER(MATCH($A9:$A11,{"Wheat","Rye"},0))*(C9:C11>0)*($B9:$B11<MMULT($C9:C11,TRANSPOSE(COLUMN($C9:C11)^0))))
EDIT: FIXED TO WORK FOR CONDITIONAL FORMATTING:
Paste this into the module:
Public Function CellColour(addr)
CellColour = Range(addr).DisplayFormat.Interior.Color
End Function
Function FINDRED(rng As Range)
FINDRED = 0
Dim cell As Range
For Each cell In rng
If (cell.Parent.Evaluate("CellColour(""" & cell.Address & """)") = RGB(255, 0, 0)) Then
FINDRED = FINDRED + 1
End If
Next cell
End Function
You can then use this like a normal excel formula:

excel 2016 - frequency formula - data array move by one row

I have approx. 100 rows by 60 columns with numbers which I'd need to be arranged in (same) bins categories. (12 bins)
In a new sheet, I used the frequency formula to look at the first row and return in an array in a column the distribution in bins. It worked for the first row of the source data but now I'd like that when I drag the formula to the next column, the data array in the frequency formula to move to the next row of the data source and return the distribution by bins.
Is it possible, can you please help with this one? Or is there any other way I can do such a bin arrangement? Need frequencies for A, B,C etc..and would like to drag the formula to the right, if that is possible.
partial data-distributed horizontally
Use the following formula for Column U:
=FREQUENCY(INDIRECT(ADDRESS(COLUMN()-19,3) & ":" & ADDRESS(COLUMN()-19,18)),$T$3:$T$17)
and drag/copy across as required. For details on INDIRECT function see this.
Note: INDIRECT is a volatile function and hence is recalculated every time anything changes in the worksheet.
See image for results based on data provided by you.

Excel array Formula that copies only cells containing a string

I would prefer to use an excel array formula (but if it can only be done in VBA, so be it) that copies ALL cells from a column array that contains specific text. The picture below shows what I am after and what I have tried. I'm getting close (thanks to similar, but different questions) but can't quite get to where I want. At the moment, I am getting only the first cell instead of all the cells. In my actual application, I am searching through about 20,000 cells and will have a few hundred search terms. I expect most search terms to give me about 8 - 12 cells with that value.
formula I am using:
=INDEX($A$4:$A$10,MATCH(FALSE,ISERROR(SEARCH($C$1,$A$4:$A$10)),0))
Spredsheet Image
To make this work efficiently, I recommend having a separate cell holding the results count (I used cell C2) which has this formula:
=COUNTIF(A:A,"*"&C1&"*")
Then in cell C4 and copied down use this array formula (The -3 is just because the header row is row 3. If the header row was row 1, it would be -1):
=IF(ROW(A1)>$C$2,"",INDEX($A$4:$A$21000,SMALL(IF(ISNUMBER(SEARCH($C$1,$A$4:$A$21000)),ROW($A$4:$A$21000)-3),ROW(C1))))
I tested this with 21000 rows of data in column A with an average of 30 results per search string and the formula is copied down for 60 cells in column C. With that much data, this takes about 1-2 seconds to finish recalculating. Recalculation time can vary widely depending on other factors in your workbook (additional formulas, nested dependencies, use of volatile functions, etc) as well as your hardware.
Alternately, you could just use the built-in Filter functionality, but I hope this helps.
You need to get the ROWS. Put this in C4 and copy down.
=IFERROR(AGGREGATE(15,6, IF(SEARCH($C$1, $A$4:$A$10)>0, ROW($A$4:$A$10)), ROW($C4)-ROW($A$4)+1), "")
Array formula so use ctrl-shift-Enter

Resources