Related
I tried everything and can't make this work.
File 1 has a date and transactions.
File 2 has date and other exported date from a software, so Column A is a date that is not formatted.
Basically I want to get the number of transactions per day on file 1, when in file 2 we have Column B with "google / cpc" and Column C contains "search".
The problem here is that I can't make the dates from File 1 to File 2 to compare to give me the transactions. It never compares.
File 1 https://docs.google.com/spreadsheets/d/1Xvoo2Rob3kI4duPpmCTfhMLPlvdzIJY9ZQBV7CHccoc/edit?usp=sharing
File 2 https://docs.google.com/spreadsheets/d/10Enq805we6_XcTkytwfj6ON1ZnITnAGUwLVoaGzXeco/edit?usp=sharing
I tried to make the date from file 2 like the date from file 1 using concatenate and LEFT and RIGHT formulas, but they look similar to the eye, but google sheets can't compare.
I tried to also change the format to date and play with it, but still can't get them to compare the dates.
you can try this out:
=MAKEARRAY(31,1,LAMBDA(r,c,INDEX(LAMBDA(z,SUM(IFNA(FILTER(INDEX(z,,6),INDEX(DATE(LEFT(INDEX(z,,1),4),MID(INDEX(z,,1),5,2),RIGHT(INDEX(z,,1),2)))=INDEX(A3:A33,r),INDEX(z,,2)="google / cpc",REGEXMATCH(INDEX(z,,3),"(?i)search")))))(importrange("10Enq805we6_XcTkytwfj6ON1ZnITnAGUwLVoaGzXeco","Sheet2!A:F")))))
they look similar to the eye, but google sheets can't compare
The values like 20230102 in spreadsheet 2 column A look like dates but are actually numbers in the neighborhood of 20 million, such as 20,230,102.
It is unclear whether your intention is to use that data in just this one report or several such reports. If the latter, you may want to Insert > Sheet in spreadsheet 1 and put this formula in cell A1 of that new 'Import' sheet to import and convert the data:
=arrayformula(
lambda(
ssId, datelikeRangeA1, criteriaRangeA1, transactionsRangeA1,
lambda(
dates, criteria, transactions,
query(
{ dates, criteria, transactions },
"select Col1, sum(Col3) where Col2 = 'google / cpc' group by Col1
label Col1 'Date', sum(Col3) 'Total transactions' ",
0
)
)(
to_date( value( regexreplace(
to_text( importrange(ssId, datelikeRangeA1) ),
"(\d{4})(\d{2})(\d{2})", "$1-$2-$3"
) ) ),
importrange(ssId, criteriaRangeA1),
importrange(ssId, transactionsRangeA1)
)
)(
"10Enq805we6_XcTkytwfj6ON1ZnITnAGUwLVoaGzXeco",
"Sheet2!A2:A",
"Sheet2!B2:B",
"Sheet2!F2:F"
)
)
The formula may look a bit complex, but it is easy to adjust to other similar imports you may need by modifying the parameters at the end. You can then more easily to refer to the data in your various reports. To match the dates in Sheet1!A3:A33, put this formula in cell Sheet1!B3:
=arrayformula(
ifna(
vlookup(
A3:A33,
Import!A2:B,
columns(Import!A2:B),
false
)
)
)
Using your current formula,try changing your values with text and back to number with value:
=INDEX(IFNA(VLOOKUP(VALUE(TEXT(A3:A33,"yyyymmdd")), QUERY(IMPORTRANGE("10Enq805we6_XcTkytwfj6ON1ZnITnAGUwLVoaGzXeco", "Sheet2!A:N"),
"select Col1,sum(Col6) where Col2 = 'google / cpc' and Col3 = 'search' group by Col1"), 2, 0)))
I'm trying to dynamically offset data of multiple rows to match the header column in Google Sheets. The first tab contains data of multiple fruits and how many are harvested on a particular day. Each fruit starts harvesting on different dates, and the dates might not be continuous.
The second tab, "Fruit bank", shows how many fruits are harvested in total for each day. Column D is a continuous set of dates. In cell E1, a QUERY formula dynamically pulls the names of the fruits so whenever a new fruit is added, it shows up here as well. In cell E2 and the rest of the row, I use VLOOKUP formulas to pull the data from the first tab. What I need help with is to write a formula on cell E2 that expands to the rest of the row so I don't have to manually type in the lookup range every time a new fruit is added.
Also, I suspect there're better functions to use than the VLOOKUP because the way VLOOKUP pulls data is very slow. I could literally see it loading even with this small dataset.
Yellow cells contain formula.
I appreciate anyone who can take a look at my spreadsheet (linked below) and see what's the best solution for this. The 3rd tab is editable.
https://docs.google.com/spreadsheets/d/14GeJKgxadInNWVVyft2gilae7HOIEvKXRop-Kz_On-Q/edit#gid=53523977
Thanks! J
Use filter(), like this:
=arrayformula(
ifna(
vlookup(
$D2:$D,
{
filter(
'Fruits data'!$B2:$AA,
'Fruits data'!$A1:$Z1 = E1
),
filter(
'Fruits data'!$A2:$Z,
'Fruits data'!$A1:$Z1 = E1
)
},
2, false
)
)
)
See your sample spreadsheet.
you can try either. added solutions here and here
=BYROW(D2:D,LAMBDA(dx,IF(dx="",,BYCOL(E1:1,LAMBDA(ex,IF(ex="",,XLOOKUP(dx,FILTER('Fruits data'!1:46,COLUMN('Fruits data'!1:1)=MATCH(ex,'Fruits data'!1:1,0)-1),FILTER('Fruits data'!1:46,'Fruits data'!1:1=ex),)))))))
OR
=MAKEARRAY(COUNTA(D2:D),COUNTA(E1:1),LAMBDA(r,c,XLOOKUP(INDEX(D2:D,r),FILTER('Fruits data'!1:46,COLUMN('Fruits data'!1:1)=MATCH(INDEX(E1:1,,c),'Fruits data'!1:1,0)-1),FILTER('Fruits data'!1:46,'Fruits data'!1:1=INDEX(E1:1,,c)),)))
try this with dates:
=ARRAYFORMULA(QUERY({
FLATTEN(FILTER('Fruits data'!A2:100, ISODD(COLUMN('Fruits data'!A2:2)))),
FLATTEN(FILTER('Fruits data'!A2:100, ISEVEN(COLUMN('Fruits data'!A2:2)))),
FLATTEN(IF(FILTER('Fruits data'!A2:100, ISEVEN(COLUMN('Fruits data'!A2:2)))="",,
FILTER('Fruits data'!A1:1, ISEVEN(COLUMN('Fruits data'!A2:2)))))},
"select Col1,sum(Col2) where Col2 is not null group by Col1 pivot Col3"))
which could be simplified:
=ARRAYFORMULA(LAMBDA(x, QUERY({
FLATTEN(FILTER(x, ISODD(COLUMN(X)))),
FLATTEN(FILTER(x, ISEVEN(COLUMN(x)))),
FLATTEN(IF(FILTER(x, ISEVEN(COLUMN(x)))="",,
FILTER(OFFSET(x, -1,,1), ISEVEN(COLUMN(x)))))},
"select Col1,sum(Col2) where Col2 is not null group by Col1
pivot Col3 label Col1'Date'"))('Fruits data'!A2:100))
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.
I have two column in a Google sheet that have values in them. Column A has all possible values (inclusive duplicate values) and Column B has some of the values in A (also inclusive duplicates).
I wanted to find out which values in Column A do not appear in Column B, also taking into account number of occurrences of these values.
The MATCH function works well however I wanted to have three instances of HQR123 appearing in the Pending column, as there are 4 occurrences of this value in Column A vs only 1 occurrence in Column B. If another instance of HQR123 is entered in Column B then only two instances should appear in the Pending column.
Is this possible?
Thanks and regards,
Shalin.
You could try something like
=sort(
index(
filter(A2:A,
isna(
match(A2:A&countifs(A2:A, A2:A, row(A2:A), "<="&row(A2:A)),
B2:B&countifs(B2:B, B2:B, row(B2:B), "<="&row(B2:B))
, 0)
))))
I have a Google Sheet (Test Sheet 2) with two sheets in it, Sheet 1 and Sheet 2. Sheet 2 is where all of the data is and I need to get the sums of the counts of that column based on three criteria into sheet 1 column C. The name, week, year and count need to match up. I used the formula
=arrayformula(iferror(vlookup(A2:A&2020&B2:B, {Sheet2!A2:A&Sheet2!B2:B&Sheet2!C2:C, Sheet2!D2:D}, 2, FALSE)))
but that only works for unique rows. In the example sheet I am providing, the formula works well for Bill, Lisa, Katie and Jon because they all have one value for 'count' from Sheet2 when the parameters of name, week and year match up. But Mike has two rows matching the criteria. This formula returns the first match which is 3. The other value is 4 so I would like the count in Sheet1 to show 7 instead of 3. I need it to add them up.
I also tried to use sumifs but the columns are two different sizes so that didn't work.
Any idea? I did try to combine sumif with the above formula but that did not work either.
Link to Test Sheet
Solution with ARRAYFORMULA and SUMIF
If you need to use ARRAYFORMULA to improve the performances you can use this tweak of the SUMIF statement: basically you can concatenate the conditions to make them create a single AND condition.
This would be a possible solution for the formula in your comment:
=ARRAYFORMULA(SUMIF(Sheet2!A2:A&Sheet2!B2:B,A2:A&2020,Sheet2!D2:D))
Solution with SUMIFS
If you are looking for a solution with the SUMIFS formula you can use this:
SUMIFS('sum_range', 'criteria_range', condition, ['criteria_range_2', condition_2])
In your case this will translate to:
=SUMIFS(Sheet2!D2:D, Sheet2!A2:A, A2, Sheet2!B2:B, 2020)
In this case the ranges dimensions won't affect the formula execution.
Just drag this formula for the Sheet1 table column and you will get the results. The drawback is that you cannot use ARRAYFORMULA with SUMIFS. Performance wise, if you have a lot of rows in the Sheet1 I suggest using the ARRAYFORMULA solution, since this will trigger a lot of formula calls instead of just one.
Try this query()
=query(Sheet2!A:D, "Select A, C, sum(D) where B = 2020 group by A, C label C 'Week', sum(D) 'Count'", 1)
UPDATED:
If you really need to use vlookup in arrayformula() you can always ise the query (that deals with the summing) as the lookup range. In the spreadsheet I used
=ArrayFormula(if(len(A2:A), iferror(vlookup(A2:A&year(D2:D)&E2:E, query({Sheet2!A:A&Sheet2!B:B&Sheet2!C:C, Sheet2!D:D}, "Select Col1, sum(Col2) where Col1 <>'' group by Col1", 1), 2, 0)),) )
and see if that helps?