I have a table with two columns which, by design, I know have the same values (here, colA and colB) but not in the same order. One of those is in the order I want (here, colA). I want to order my whole table, except this column (colA), so that another column (here, colB) is in the order of the column in the right order (colA).
Example:
colA colB colC
5 3 is
7 5 hello
3 7 this
4 4 dog
Desired result:
colA colB colC
5 5 hello
7 7 this
3 3 is
4 4 dog
(Notice that the values in colC (and other columns) follow those in colB) (each value in colA and colB is unique). Doing this in google sheets.
try:
=INDEX(IFNA(VLOOKUP(A1:A4, B1:C4, {1, 2}, 0)))
or see: https://webapps.stackexchange.com/a/126631/186471
Insert another column before A and give them a index starting at 1... 1,2,3,4... This will be used to do a final sort... Now all the columns are named differently then your example so take that into account when reading the below...
colA colB colC colD
1 5 3 is
2 7 5 hello
3 3 7 this
4 4 4 dog
Next sort colC and colD (and any other cols) in order of colC. Sort colA and colB in order of colB. Now the numbers in colB and ColC should match. Finally sort all by colA. Delete colA
Related
I'm trying to count the number of occurrence in previous rows based on two conditional values using Google Sheet.
Let say this is my table :
Row A
Row B
Row C
Row D
1
John
Smith
2
Marty
Butler
3
John
Herbert
4
John
Smith
5
Philip
Rand
6
John
Smith
7
Marty
Butler
Is there a formula that exist that can count those occurrences. The idea is that when I log a new name, if Row B and C already exist it increase the value in Row D by 1 so I would know that it is the nth entry under that name. In my example, Row D would looks like this:
Row A
Row B
Row C
Row D
1
John
Smith
1
2
Marty
Butler
1
3
John
Herbert
1
4
John
Smith
2
5
Philip
Rand
1
6
John
Smith
3
7
Marty
Butler
2
Delete everything in Column D (including the header) and place the following in D1:
=ArrayFormula({"Header";IF(B2:B="",,COUNTIFS(B2:B&C2:C,B2:B&C2:C,ROW(A2:A),"<="&ROW(A2:A)))})
The "Header" text can be edited as you like.
The COUNTIFS reads, in plain English, "Count how many times this first and last name combination has occurred within only the rows up to the current row."
I have a table in my Google Spreadsheet that looks like this :
Row
(A) Some day
(B) Some data
1
day 1
5
2
day 2
10
3
total
4
day 1
8
5
day 2
7
6
day 3
9
7
total
Where I can have multiple "day rows", but I don't know how many. It can be only 1 like it can be 20 "day rows". And I want the "total row" to automatically do a SUM of the "day rows" above.
Result expected :
Row
(A) Some day
(B) Some data
1
day 1
5
2
day 2
10
3
total
15
4
day 1
8
5
day 2
7
6
day 3
9
7
total
24
Where B3 is equal to SUM(B1:B2) and B7 is equal to SUM(B4:B6)
I am trying to do that without the App Script, just using Spreadsheet native functions.
I think I should be using the SUM function or the Query function, but I don't know how to dynamically get the right range. Do you have any idea how to do that ?
Thank you
In your example, column B would be a mixture of constants and formulas. That would require a script to deposit the formulas. However with an extra column, you can avoid scripts. In C2 enter:
=if(A2<>"Total","",sum($B$1:$B1)-sum($C$1:C1))
and copy downwards:
Basically we add column B and subtract any previous Totals in column C.
Another approach is to place the following single array formula in C1:
=ArrayFormula(IF(A:A="",, SUMIF(IF(ROW(A:A),ROW(A:A)), "<="&ROW(A:A),B:B) - SUMIF(IF(ROW(A:A), ROW(A:A)),"<="& VLOOKUP(ROW(A:A)-1, FILTER(ROW(A:A), A:A="total"), 1, TRUE), B:B)))
If you only want to see the values for the "total" rows, change the opening
IF(A:A=""
to
IF(A:A<>"total"
The short version of how it works is that a sum is made of all values up to the current row in B:B, and from that is subtracted any values up to the last listing of the word "total" in A:A.
paste in each cell in B column where A column = total
=INDEX(SUM(IFERROR(1*INDIRECT(ADDRESS(MATCH(INDEX(
COUNTIFS({"total";A:A}, {"total";A:A}, {"total";A:A}, "=total",
{ROW(A:A);ROW()}, "<="&{ROW(A:A);ROW()})-1, ROW()+1, 1),
COUNTIFS({"total";A:A}, {"total";A:A}, {"total";A:A}, "=total",
{ROW(A:A);ROW()}, "<="&{ROW(A:A);ROW()}), 0), 2)&":"&
ADDRESS(ROW()-1, 2)), 0)))
In a worksheet of multiple sheets, I have Sheet1, e.g. with the following: (these rows will be less or more and are manually entered)
Sheet1
A B C
1 APPLE ORANGE LEMON
2 bravo chair mars
3 charlie table jupiter
4 alpha box venus
5 delta saturn
6 foxtrot
I would like some help in constructing Sheet2 via formulas so that it rearranges data from Sheet1 as follows
Sheet2 (Desired result)
A B
1 APPLE
2 bravo
3 charlie
4 alpha
5 delta
6 foxtrot
7
8 ORANGE
9 chair
10 table
11 box
12
13 LEMON
14 mars
15 jupiter
16 venus
17 saturn
It probably needs some combination of QUERY() ARRAYFORMULA(), TRANSPOSE() and/or INDEX() but I need some help with getting started and having them into lesser columns (and more rows.) as shown. Please note that Sheet1's data will keep changing in number of rows (or columns) so Sheet2 needs to adapt to that.
Thank you.
You can try following formula:
=ArrayFormula(
{FILTER(
FLATTEN(TRANSPOSE(IF(ROW(A:F)=1;A:F;"")));
FLATTEN(TRANSPOSE(A:F))<>"")
\FILTER(
FLATTEN(TRANSPOSE(IF(ROW(A:F)<>1;A:F;"")));
FLATTEN(TRANSPOSE(A:F))<>"")}
)
if you use semicolon as function argument separator.
If you use comma, change to
=ArrayFormula(
{FILTER(
FLATTEN(TRANSPOSE(IF(ROW(A:F)=1,A:F,""))),
FLATTEN(TRANSPOSE(A:F))<>"")
,FILTER(
FLATTEN(TRANSPOSE(IF(ROW(A:F)<>1,A:F,""))),
FLATTEN(TRANSPOSE(A:F))<>"")}
)
The formula will run faster if you specify a row constraint.
Let us assume we have the following tow columns :
column 1
1
3
5
column 2
2
4
6
the result column
1
2
3
4
5
6
and in case the two columns are not equal in size, the combined result should be without empty cells at the end!
=FLATTEN(A1:B)
=TRANSPOSE(SPLIT(TEXTJOIN("♦", 1, A1:B), "♦"))
=INDEX(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(A1:B="",,"♦"&A1:B)),,99^99)),,99^99), "♦")))
I have a google spreadsheet that has 6 cells with specific numbers in them. Every week, a series of numbers is entered in and I would like to flag the numbers in a separate column if they appear for that week. I was using the formula below where my numbers are in D2->I2 and the weekly ones would be in D18->I18 for example.
=arrayformula(sumproduct((D2:I2=D18:I18)))
Now, while this works, it's not quite what I'm trying to do. Unless the numbers match each other exactly, 1 2 3 4 5 6 to 1 2 3 4 5 6 then the addition doesn't happen. What I would like to have happen is that if, for example, the master column has 1 2 3 4 5 6 and the weekly column has 3 7 9 1 8 5 then the cell with the formula would display the value of 3 for matching three of the numbers that week.
Does anyone have a suggestion on how best to accomplish this?
See if this works ?
=ArrayFormula(sum(--regexmatch(D2:I2&"", join("|", D18:I18&""))))
with exclusion of empty cells in both ranges:
=iferror(ArrayFormula(sum(--regexmatch(to_text(filter(D2:I2, len(D2:I2))), "\b("&join("|", to_text(filter(D18:I18, len(D18:I18))))&")\b"))))