I want to collect only the rows which are different between two tables.
The PK are the first two columns.
How can I fix this formula? I guess I use V:W incorrectly.
=if(Q11&" "&R11="","", isnumber(match(Q11&" "&R11, V:W,0)))
Let's say that you have 'today' data in column B
And 'last time' data in column C
And you want to get values that exist only in 'today' column but not in 'last time'.
You can use:
=query(
ArrayFormula(
if(countif(C2:C,B2:B)=0,
B2:B,
""
)),
"select Col1 where Col1 <> ''"
)
As you use more columns in your datatable, you can concatenate and use for example: C2:C&" "&D2:D&" "&E2:E instead of one column.
Related
I have a Google sheet which has columns with the same name and there are different values under each column. I want to count the same value that appear under the same column name.
1
2
3
1
2
R
B
C
R
D
D
C
R
B
D
For example, I would like to get the number "R" that appear under column "1", so I would expect a count of 2 for "R" appearing under columns 1.
Here is a link to Google Sheet with actual data.
I have tried countif and countifs in Google Sheets, but can't figure out how to get the count right based on column name.
Try this formula, it outputs an array which shows how many of each letters are contained in each column name:
=LAMBDA(NUMBERS,LETTERS,
LAMBDA(UNUM,ULET,
{
{"",TRANSPOSE(UNUM)};
{ULET,
MAKEARRAY(COUNTA(ULET),COUNTA(UNUM),LAMBDA(ROW,COL,
COUNTIF(FILTER(LETTERS,NUMBERS=INDEX(UNUM,COL)),INDEX(ULET,ROW))
))
}
}
)(UNIQUE(FLATTEN(NUMBERS)),UNIQUE(FLATTEN(LETTERS)))
)($A$1:$AE$1,$A$2:$AE$18)
Assume that your sample datarange is A1:AE18.
apply UNIQUE() and FLATTEN() to A1:AE1, to get the unique entries of column names.
apply UNIQUE() and FLATTEN() to A2:AE18, to get the unique entries of data.
use LAMBDA() to name the dataranges and output of step 1 & 2 as:
NUMBERS (=A1:AE1),
LETTERS (=A2:AE18),
UNUM (=UNIQUE(FLATTEN(NUMBERS))),
ULET (=UNIQUE(FLATTEN(LETTERS))).
create Arrays with {}, which...
1st column's value is a blank, followed by TRANSPOSE(UNUM) in the row,
1st row's value is a blank, followed by ULET in the column.
inside the above said range, use MAKEARRAY() to create results.
MAKEARRAY() set an array by defining the length of ROW and COL, which we uses...
COUNTA(ULET) as the number of rows and,
COUNTA(UNUM) as the number of columns.
inside MAKEARRAY(), you also need a LAMBDA() to apply what to do with each CELL of the new created array, each CELL is accessed by the ROW and COL index.
in our case, we set up the row and col number of the new array using ULET and UNUM. Therefor, the index of each CELL of the new array will be equal to the index of each value inside ULET and UNUM, we can than take that as reference and use COUNTIF() with FILTER() to calculate the number of repeats of each letter in each column name.
You can try this:
= ARRAYFORMULA(
query(
query(
SPLIT(TRANSPOSE(SPLIT(
QUERY(
TRANSPOSE(
QUERY(
TRANSPOSE(
IF(Original!A2:AE18<>"",
"๐"&Original!A1:AE1&"โฅ"&Original!A2:AE18, )
),,999^99)
),,999^99),
"๐")),
"โฅ"),
"Select Col1,Col2,count(Col2) group by Col1,Col2"),
"Select max(Col2),Col3 group by Col2,Col3 pivot Col1")
)
Note: (Got inspired by player0 useful answers)
Output:
We can read from the table that: R is appearing 40 times under the column named '1', 24 times under the colum named '2', etc...
The following is a more compact approach than the previous answers:
=arrayformula(query(split(flatten(A1:AE1&"|"&A2:AE18),"|"),"select Col2,count(Col2) group by Col2 pivot Col1"))
N.B. I'm assuming the order of the grouped values in each column is irrelevant, so the QUERY default of lexicographical ordering is fine.
Right now I am using this query to search for a row based on its Column 1 value. Then it takes the value from the last column. I need a way for it to automatically find the last column in the row since some of the rows have more columns than others.
This is what I had before, which I had manually specified the last column with a value:
=QUERY(IMPORTRANGE("link_redacted","PriceList!A1:AZ100000"), "Select Col10 where Col1 = '5531001'",1)
I have tried using LOOKUP with ARRAYFORMULA I couldn't get it to work:
=QUERY(IMPORTRANGE("link_redacted","PriceList!A1:AZ100000"), "Select (LOOKUP(1, ARRAYFORMULA(1/[Select Col1 where Col1 = '5531006']:[Select Col100 where Col1 = '5531006']<>"")[Select Col1 where Col1 = '5531006']:[Select Col100 where Col1 = '5531006']))",1)
Any ideas for a simpler way to do this?
Since no example is presented, I tested the formulas given but no source data is fetched.
so i created a a minimal, reproducible example
Example is the data on the left
Use this formula to get the last non empty columns values.
=ArrayFormula(IFERROR( REGEXEXTRACT( TRIM(TRANSPOSE(QUERY(TRANSPOSE(C3:E),,ROW(C3:E)))), "[^\s]+$")))
The data is currently all in Column A, with commas separating multiple values in each row. How can I separate the data in each row and then stack them into one column (sorting by the number of values- so the rows with one value will go first in the column, followed by two values, and then rows with three values, etc.)
A1: ibnuaaabbb
A2: theresiaaaabbb
A3: virnaaaabbb , iskandaraaabbb
A4:zakiaaaabbb , vebrinaaaabbb , salsabilaaaabbb , rizkullahaaabbb , rimaaaabbb , noviaaabbb , lanaaaabbb , kintanaaabbb , jhonaaabbb , iskandaraaabbb , ilfaaaabbb
A5: afifahaaabbb
Would like to stack into:
A1: ibnuaaabbb
A2: theresiaaaabbb
A3: afifahaaabbb
A4: virnaaaabbb
A5: iskandaraaabbb
A6: zakiaaaabbb
A7: vebrinaaaabbb
A8: salsabilaaaabbb
etc.
I have got this, but it is probably a bit inefficient:
=ArrayFormula(trim(index(sort(query(split(flatten(len(A:A)-len(substitute(A:A,",",""))+1&"|"&split(A:A,",",true)),"|"),"select Col1,Col2 where Col2 is not null"),1,1),0,2)))
use:
=INDEX(QUERY(TRIM(SPLIT(FLATTEN(SPLIT(A1:A, ",")&"ร"&
TEXT(LEN(REGEXREPLACE(A1:A&"", "[^,]", )), "\ยค00000#")), "ร")),
"select Col1 where Col2 is not null order by Col2"))
Place the following into an EMPTY cell. You cannot put a formula in a cell that contains the data the formula is using.
=transpose(SPLIT(join(",",A:A),","))
This takes all the values in the columns and creates a single string with all values separated by commas.
Then it splits that string into individual columns using the coma as a delimiter.
Finallly, It takes those columns and transposes them into rows.
I have been using this and it works, but everyday I add a new row and have to insert a row above this formula, that's why I want it to display in column "F" somewhere:
=SUM(INDIRECT(ADDRESS(ROW()-10,COLUMN(),4) &":"& ADDRESS(ROW()-1,COLUMN(),4)))
You can try SUMPRODUCT:
=SUMPRODUCT((ROW(A:A)<=COUNTA(A:A))*(ROW(A:A)>COUNTA(A:A)-10)*A:A)
There can't be blanks in A:A
If your range of values in D:D is contiguous (i.e., no blanks) and begins at the top of the column (with or without a header), you can use this:
=ArrayFormula(SUMIF(ROW(D:D),">"&COUNTA(D:D)-10,D:D))
If there are interspersed blanks in the range, you can use either of these:
=SUM(SORTN(FILTER(D:D,ISNUMBER(D:D)),10,0,FILTER(ROW(D:D),ISNUMBER(D:D)),0))
=SUM(QUERY(FILTER({D:D,ROW(D:D)},ISNUMBER(D:D)),"Select Col1 ORDER BY Col2 DESC LIMIT 10"))
use:
=SUM(QUERY(SORT(D2:D; ROW(D2:D); );
"where Col1 is not null limit 10"; ))
Cannot figure out how to pull the results of a query with multiple rows and columns into single cells and find their details from my lookup table. Any help is greatly appreciated.
Trying this
=ArrayFormula(
QUERY({
QUERY({A4:A16,TEXTJOIN(",",TRUE,B4:C16)}, "SELECT Col1, Col2, Col3 WHERE Col1 MATCHES 'Core 1|Core 2|Core 3' LABEL Col1 'Core ID', Col2 'Full Result'")
}, "SELECT Col2 WHERE Col1 = Col1")
)
Sheet to help
It's always a headache trying to mix Query with ArrayFormula. They don't go well together.
I arrived at a nice formula, but the catch is that it relies on you sorting your data by Core Item first. You can easily achieve this with:
=SORT(A4:C16)
For this example, I placed this formula is cell N4. Then your resultant formula is:
=ArrayFormula(
{
"Core ID", "Full Result";
UNIQUE(FILTER(N4:N,N4:N<>"")),
SUBSTITUTE(
TRANSPOSE(
SPLIT(
REGEXREPLACE(
TEXTJOIN(
",",
,
UNIQUE(
TRANSPOSE(
IF(
TRANSPOSE(FILTER(N4:N,N4:N<>""))=FILTER(N4:N,N4:N<>""),
FILTER(O4:O,O4:O<>"")&
" ("&
VLOOKUP(FILTER(O3:O,O3:O<>""),A23:B53,2,)&
") - "&
FILTER(P4:P,P4:P<>"")&
" ("&
VLOOKUP(FILTER(P4:P,P4:P<>""),A23:B53,2,)&
")",
";"
)
)
)
),
",(;,)+",
";"
),";"
)
),
",",
CHAR(10)
)
})
It uses the Group Concatenate method I've adopted for stuff like this with UNIQUE, TRANSPOSE, and IF. This can probably be solved without using the precalculated SORT by substituting all instances of the N4:N, but doing it this way saves on computation time. If you need it gone, you can also hide the column or stow it in another sheet.
If you are ok breaking apart your formula then this would be an acceptable approach.
Start by Building your query criteria.
=ArrayFormula(
QUERY({QUERY({A4:A16,ArrayFormula(B4:B16&" ("&VLOOKUP(B4:B16,A23:B53,2,false)&") -
("&VLOOKUP(C4:C16,A23:B53,2,false)&")")}, "SELECT Col1, Col2 WHERE
Col1 MATCHES 'Core 1|Core 2|Core 3' LABEL Col1 'Core ID', Col2 'ALL Result'")},
"SELECT Col1, Col2 WHERE Col1 = Col1"))
Then in another column get the unique values and lastly, join the filtered values.
=UNIQUE(E4:E17)
=Join(Char(10),FILTER(F4:F12,E4:E12 = H4))
The downside to this is you will need to have multiple columns to achieve your desired result but it is easy to follow. Good luck!