I have a set of ID's to compare to a SDE, and I would like to pull multiple rows from the SDE using the ID's as a reference. The reason I want to lookup nth instances is because I have multiple columns in which each column will pull a different instance so all the data can be store horizontally instead of vertically. There will be more ID's but the two on there are just for testing purposes.
The current function I have is =ARRAYFORMULA(IF(C4:C="",,INDEX(SDE_materials_mat,SMALL(IF(C4:C=SDE_materials_id,ROW(SDE_materials_mat)),1))))
That function displays the following alarm:
Array arguments to EQ are of different size.
Here is a copy of the sheet:
https://docs.google.com/spreadsheets/d/1uPgFYKjfkcLfBTAcuPL__gDYeCmn1Nwu473CFMepaUk/edit?usp=sharing
Thank you in advance for any help, it's very appreciated!
try:
=ARRAYFORMULA(IFERROR(SPLIT(IFNA(VLOOKUP(C4:C, SPLIT(FLATTEN(QUERY(QUERY(FILTER(
{SDE_invTypeMaterials!B2:B&"¤"&SDE_invTypeMaterials!C2:C, SDE_invTypeMaterials!A2:A&"×"},
REGEXMATCH(SDE_invTypeMaterials!A2:A&"", TEXTJOIN("|", 1, C4:C)),
COUNTIFS(SDE_invTypeMaterials!A2:A, SDE_invTypeMaterials!A2:A,
ROW(SDE_invTypeMaterials!A2:A), "<="&ROW(SDE_invTypeMaterials!A2:A))<7),
"select max(Col1) where Col1 is not null group by Col1 pivot Col2"),,9^9)), "×"), 2, 0)), "¤ ", 1)))
Related
Is there a way to get the result column in the picture below?
All i want to do is text join the Col1 if the corresponding Col2 belongs to the same groups (E.G. 1,2,3....).
Reminded that I want to use arrayformula instead of dragging down the "normal" formula myself everytime.
Use this formula
Or Make a copy of this example sheet.
=ArrayFormula({"Result";
IF(A2:A="",,
BYROW(B2:B,
LAMBDA(v,JOIN(", ",FILTER(A2:A,B2:B=v)))))})
Great news for google-sheet lovers that google releases new lambda formulas. You can use BYROW() function to make it spill array. Try below formula.
=BYROW(C3:C9,LAMBDA(x,JOIN(",",FILTER(B3:B9,C3:C9=x))))
To refer entire column use FILTER() function for BYROW().
=BYROW(FILTER(C3:C,C3:C<>""),LAMBDA(x,JOIN(",",FILTER(B3:B,C3:C=x))))
Suppose my range of data from B3:C9, want to group the result according the the Column C (or Col2)
Here is the formula i googled without using the Lambda function
=ARRAYFORMULA(REGEXREPLACE(TRIM(SPLIT(FLATTEN( QUERY(QUERY({ROW(C3:C9), C3:C9&"×", B3:B9&","}, "select max(Col3) where not Col2 starts with '×' group by Col1 pivot Col2"),,7^7)), "×")), ",$", ))
Notice the 7^7 is the (length of the data)^(length of the data).
i.e. from 3 to 9, there are 7 data.
I'm looking for an efficient way to gather and aggregate some date in Google Sheets. I've been looking at the query function, pivot tables, and Index + Match formulas, but so far I've not found a way that brings me to the result I'm looking for. I have a set of data which looks more or less as follows.
The fields with an X represent irrelevant data which I don't want to show up in my end result. They only serve to illustrate that there are columns of data that I don't want in between the columns of data that I do want. The data in those columns is of varying types and of varying values per type, they are not actually fields with an "X" in it. Only the fields with numbers are of interest along with the related names at the top and left of those. The intent is to create a list that looks more or less like this.
I've highlighted those yellow fields because that data has been aggregated. For example, in the original file field D3 shows a relation between Laura and Pete with the number 1, and field L3 also shows a relation between Laura and Pete, so the number in that field is to be added to the number in the other field resulting in an aggregated total of 2 for that particular combination.
I would really appreciate any suggestions that can help me get to an elegant and efficient solution for this. The only solutions I can come up with would involve multiple "in-between" sheets and there just has to be a better way.
UPDATE:
Solved by applying the solution in player0's answer. I just had to switch around the order of Col1 and Col2 in the formula to get the table sorted the way I needed it. Formula looks like below now. Many thanks to both player0 and Erik Tyler for their efforts.
=INDEX(QUERY(SPLIT(FLATTEN(A2:A&"×"&D1:N1&"×"&D2:N), "×"),
"select Col2,Col1,sum(Col3)
where Col2 is not null
and Col3 is not null
group by Col2,Col1
label sum(Col3)''", ))
try:
=INDEX(QUERY(SPLIT(FLATTEN(A2:A&"×"&D1:N1&"×"&D2:N), "×"),
"where Col3 is not null and Col2 is not null", ))
update:
=INDEX(QUERY(SPLIT(FLATTEN(A2:A&"×"&D1:N1&"×"&D2:N), "×"),
"select Col1,Col2,sum(Col3)
where Col3 is not null
and Col2 is not null
group by Col1,Col2
label sum(Col3)''", ))
Given your current data set (which only appears to extend to Col N), place the following somewhere to the right of Col N:
=ArrayFormula(SPLIT(TRANSPOSE(QUERY(TRANSPOSE(QUERY(SPLIT(QUERY(FLATTEN(FILTER(IF(NOT(ISNUMBER(D2:N)),,D1:N1&"~ "&A2:A&"|"&D2:N),A2:A<>"")),"Select * WHERE Col1 Is Not Null"),"|"),"Select Col1, SUM(Col2) GROUP BY Col1 LABEL SUM(Col2) ''")&"~ "),,2)),"~ ",0,1))
It would be better if this were placed in a different sheet from the original data. Supposing that your original data sheet is named Sheet1, place the following version of the above formula into a new sheet:
=ArrayFormula(SPLIT(TRANSPOSE(QUERY(TRANSPOSE(QUERY(SPLIT(QUERY(FLATTEN(FILTER(IF(NOT(ISNUMBER(INDIRECT("Sheet1!D2:"&ROWS(Sheet1!A:A)))),,Sheet1!D1:1&"~ "&Sheet1!A2:A&"|"&INDIRECT("Sheet1!D2:"&ROWS(Sheet1!A2:A))),Sheet1!A2:A<>"")),"Select * WHERE Col1 Is Not Null"),"|"),"Select Col1, SUM(Col2) GROUP BY Col1 LABEL SUM(Col2) ''")&"~ "),,2)),"~ ",0,1))
This separate-sheet approach and formula allows for the original data to extend indefinitely past Col N.
I am trying to transpose data from column A to single rows. The original data has 3 rows for each name. But there could be either 1 or several jobs for each day. Each day needs to be treated separately, but this maybe best handled by manually adding at the beginning of each day.
This is for a fortnightly timesheet, therefore the number of rows in unpredictable.
The 1st image is my original data. the 2nd is the desired end result.
The data is to transposed to any blank rows in columns b, c, d, e,
as long as there are no blank rows, I can then reference them with my formulas.
to place the information into the appropriate cells within
the timesheet. I already have working formulas to do this.
the transpose section is what I need help with
Here is a link to my file
https://docs.google.com/spreadsheets/d/1PhuFXDB2H1c9ua6szjhJEgJR91yXHhZAmn_2UGOBvIo/edit?usp=sharing
try:
=ARRAYFORMULA({QUERY(IF(REGEXMATCH(A12:A, "\d+:\d+.*"), VLOOKUP(ROW(A12:A),
IF(IF(IFERROR(RIGHT(A12:A, 4)*1)>2000, A12:A, )<>"", {ROW(A12:A),
IF(IFERROR(RIGHT(A12:A, 4)*1)>2000, A12:A, )}), 2, 1), ), "where Col1 is not null"),
QUERY(IF((IFERROR(RIGHT(A12:A, 4)*1)>2000)+(REGEXMATCH(A12:A, "\d+:\d+.*")),, A12:A),
"where Col1 is not null skipping 2"),
QUERY(QUERY(IF((IFERROR(RIGHT(A12:A, 4)*1)>2000)+(REGEXMATCH(A12:A, "\d+:\d+.*")),, A12:A),
"where Col1 is not null offset 1", 0), "skipping 2"),
FILTER(A12:A, REGEXMATCH(A12:A, "\d+:\d+.*"))})
If you want a solution with a formula in one cell only, try:
=arrayformula({"date","name","job type","start - end time";query(split(flatten(query(iferror(datevalue(A12:A),),"where Col1 is not null",0)&split(flatten(split(textjoin(char(9999),1,if(regexmatch(to_text(A12:A),":+.*-+"),A12:A&char(9998),if(iferror(datevalue(A12:A),)<>"",char(10001),A12:A))),char(10001))),char(9998))),char(9999)),"where Col2 is not null",0)})
in put B12 :
=IFERROR(if(FIND("2021",A12)>=1,0,""),B11+1)
in put C12 :
=if(B12=0,A12,C11)
in D12 :
=if(mod(B12,3)=1,TRANSPOSE(A12:A14),"")
and drag downwards. Then in F12 put :
=FILTER(C:F,F:F<>"")
and drag downwards.
Idea : use transpose() with a conditional counter. use (F12)filter to remove blank.
Please if it works/understandable/not.
I have searched on a lot of pages but I cannot find a solution to my problem except in reverse order. I have simplified what I do, but I have a query that comes looking for information in my data sheet. Here there are 3 columns, the date, the amount and the source.
I would like, with a query function, to be able to make different columns which counts the information of column C based on the values of its cells per month, like this
I'm okay with the start of the formula
=QUERY(A2:C,"select month(A)+1, sum(B), count(C) where A is not null group by month(A)+1")
But as soon as I try a little different things by putting 2 query together in an arrayformula, obviously the row count doesn't match as some minus are 0 for some sources.
Do you have a solution for what I'm trying to do? Thank you in advance :)
Solution:
It's not possible in Google Query Language to have a single query statement that has one result grouped by one column and another result grouped by another.
The first two columns can be like this:
=QUERY(A2:C,"select month(A)+1, sum(B) where A is not null group by month(A)+1 label month(A)+1 'Month', sum(B) 'Amount'")
To create the column labels for the succeeding columns, use in the first row, in my example, I1:
=TRANSPOSE(UNIQUE(C2:C))
Then from cell I2, enter this:
=COUNTIFS(arrayformula(month($A$2:$A)),$G2,$C$2:$C,I$1)
Then drag horizontally and vertically to apply to the entire table.
Results:
try:
=INDEX({
QUERY({MONTH(A2:A), B2:C},
"select Col1,sum(Col2) where Col2 is not null group by Col1 label Col1'month',sum(Col2)'amount'"),
QUERY({MONTH(A2:A), B2:C, C2:C},
"select count(Col3) where Col2 is not null group by Col1 pivot Col4")})
I'll post a link to the spreadsheet at the bottom of this write-up.
I'm trying to work out the average of a column of numbers that fall between a date range. The formula below works but I have to drag it down the column, I want it to be an array so it auto updates.
=iferror(averageifs(B$2:B,A$2:A,">="&C2,A$2:A,"<="&D2),1)
So I created it as an array as follows:
=iferror(ArrayFormula(averageifs(B$2:B,A$2:A,">="&C2:C,A$2:A,"<="&D2:D)),1
But it stops after the first cell. So I broke up the average function into sum & count in order to divide.
The count array works using this formula:
=iferror(ArrayFormula(countifs(A$2:A,">="&C2:C,A$2:A,"<="&D2:D)),1)
However the sum array does not even go past the first cell:
=iferror(ArrayFormula(SUMIFS(B$2:B,A$2:A,">="&C2:C,A$2:A,"<="&D2:D)),1)
And the combination gets past the first cell but the calculations all come to zero:
=ArrayFormula(iferror(SUMIFS(B$2:B,A$2:A,">="&C2:C,A$2:A,"<="&D2:D)/countifs(A$2:A,">="&C2:C,A$2:A,"<="&D2:D),1))
What I'm trying to achieve is an average for the previous month.
If anyone can help me I'd be very grateful!
https://docs.google.com/spreadsheets/d/1XhoLl5hB-MpXFz9VS2aLqJOWbXk1d_7apnwKWFdDUlg/edit?usp=sharing
you are trying to apply a bit weird structural logic with lots of repeating values with no reason. basically, it looks like you need this:
=ARRAYFORMULA(QUERY({TEXT(A2:A, "yyyy-mmm"), B2:B},
"select Col1,avg(Col2)
where Col2 is not null
group by Col1
order by avg(Col2) desc
label avg(Col2)''", 0))
but if you really really need so:
=ARRAYFORMULA(IF(LEN(A2:A),
IFERROR(VLOOKUP(TEXT(DATE(YEAR(A2:A), MONTH(A2:A)-1, 1), "yyyy-mmm"),
QUERY({TEXT(A2:A, "yyyy-mmm"), B2:B},
"select Col1,avg(Col2)
where Col2 is not null
group by Col1", 0), 2, 0), 0), ))