Exemple: https://docs.google.com/spreadsheets/d/1o6088xXfnEYn-RflrPvY3e_OGJyrI3-tMIb3tFbm6e8/edit?usp=sharing
I have a question about google sheets, columns id 1 and id 2 have codes that together result in a unique code like column unique id. But, occurs a repetition between columns id 1 and id 2 and I would like to know how to highlight that repetition where the unique id is return. Like in row 3 and 8.
I try something like this:
=QUERY(B3:D10;"select B where "JOIN("",C,D)"="JOIN("",D,C)" ")
=FILTER(C3:D11;CONCAT(C3:D3)=CONCAT(C3:D3))
The expected result is something like line 15 of the example.
To find rows where both IDs are duplicates of IDs found in another row, use filter(), like this:
=let(
data; B3:D11; id_1; C3:C11; id_2; D3:D11;
compoundIds;
map(
id_1; id_2;
lambda(
c; d;
if(c < d; c & "→" & d; d & "→" & c)
)
);
filter(
data;
countif(compoundIds; compoundIds) > 1
)
)
If you do not have the recently introduced let() function yet, use lambda() instead:
=lambda(
data; id_1; id_2;
lambda(
compoundIds;
filter(
data;
countif(compoundIds; compoundIds) > 1
)
)(
map(
id_1; id_2;
lambda(
c; d;
if(c < d; c & "→" & d; d & "→" & c)
)
)
)
)(
B3:D11; C3:C11; D3:D11
)
To highlight duplicates in the list, use this conditional formatting custom formula rule for the range C3:D11:
=len($F3:$F11)
...and fill column F with this formula in cell F3:
=let(
ids; B3:B11; id_1; C3:C11; id_2; D3:D11;
compoundIds;
map(
id_1; id_2;
lambda(
c; d;
if(c < d; c & "→" & d; d & "→" & c)
)
);
map(
ids; compoundIds;
lambda(
id; compoundId;
if(
countif(compoundIds; compoundId) > 1;
id & " = " &
join( ", "; filter(ids; row(ids) <> row(id); compoundIds = compoundId) );
iferror(1/0)
)
)
)
)
...or use the equivalent lambda:
=lambda(
ids; id_1; id_2;
lambda(
compoundIds;
map(
ids; compoundIds;
lambda(
id; compoundId;
if(
countif(compoundIds; compoundId) > 1;
id & " = " &
join( ", "; filter(ids; row(ids) <> row(id); compoundIds = compoundId) );
iferror(1/0)
)
)
)
)(
map(
id_1; id_2;
lambda(
c; d;
if(c < d; c & "→" & d; d & "→" & c)
)
)
)
)(
B3:B11; C3:C11; D3:D11
)
To find rows where id_1 is a duplicate of an id_2 found in the other column in another row, use:
=filter(
B3:C11;
countif(D3:D11; C3:C11)
)
To get the IDs of the duplicates, use vlookup(), like this:
=arrayformula( iferror( vlookup(C18:C; { D3:D11 \ B3:B11 }; 2; false) ) )
To highlight duplicates in the list, use this conditional formatting custom formula rule for the range C3:D11:
=countif($C$3:$D$11; C3) > 1
See your sample spreadsheet.
As shown above, in the event your spreadsheet locale uses comma , as decimal separator, you will have to use semicolon ; as formula argument separator and backslash '\' as { array expression } horizontal separator. If your spreadsheet uses period . as decimal mark, use comma , for both those purposes.
Added solution to your sheet here:
=byrow(C3:D11;lambda(z;JOIN("|";TOROW(SORT(TOCOL(z);1;1)))))
Related
I have rows with start and end date. I need to repeat each row N times and increment new date column by one.
N = the number of days between the start date and en date
My table:
Column A
Start date
End date
A
10/09/2022
12/09/2022
B
15/09/2022
16/09/2022
C
08/09/2022
12/09/2022
The result I'd like to generate automatically (new row will often be added):
Column A
Start date
End date
Date
A
10/09/2022
12/09/2022
10/09/2022
A
10/09/2022
12/09/2022
11/09/2022
A
10/09/2022
12/09/2022
12/09/2022
B
15/09/2022
16/09/2022
15/09/2022
B
15/09/2022
16/09/2022
16/09/2022
C
08/09/2022
12/09/2022
08/09/2022
C
08/09/2022
12/09/2022
09/09/2022
C
08/09/2022
12/09/2022
10/09/2022
C
08/09/2022
12/09/2022
11/09/2022
C
08/09/2022
12/09/2022
12/09/2022
I hope my need is clear.
Thanks,
I've tried THIS, but the solution is for fixed N times while I need N to be dynamic.
UPDATE
I though it'll be easy to reproduce the solution to my exact need, but it's not the case... I've received two great solutions which work with my first example, but not the full need.
Here is an example of the exact need:
Col1
Col2
Col3
Col4
Col5
Col6
Col7
Col8
Start date
End date
Col11
Col12
Col13
Col14
Col15
Col16
Col17
Col18
Col19
A
B
C
D
E
F
G
H
10/09/2022
24/09/2022
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
A
05/10/2022
17/11/2022
D
E
F
G
H
I
J
K
L
try:
=QUERY(ARRAYFORMULA(SPLIT(FLATTEN(A2:A&"|"&B2:B&"|"&C2:C&"|"&MAP(B2:B,C2:C,LAMBDA(bx,cx,if(bx="",,TRANSPOSE(SEQUENCE(DATEDIF(bx,cx,"d")+1,1,bx,1)))))),"|")),"Select * Where Col4 IS NOT NULL")
-
Here's one way to do that using REDUCE.
=ARRAYFORMULA(
{A1:C1,"Date";
QUERY(
REDUCE(
{"","","",""},
BYROW(
FILTER(A2:C,A2:A<>"",B2:B<>"",C2:C<>""),
LAMBDA(row,JOIN("❄️",row))),
LAMBDA(acc,cur,
{acc;
LAMBDA(a,start,end,
LAMBDA(dif,
{IF(dif,{a,start,end}),SEQUENCE(MAX(dif),1,start)})
(SEQUENCE(end-start+1)))
(INDEX(SPLIT(cur,"❄️"),,1),
INDEX(SPLIT(cur,"❄️"),,2),
INDEX(SPLIT(cur,"❄️"),,3))})),
"OFFSET 1",0)})
UPDATE
=ARRAYFORMULA(
QUERY(
{TRIM(QUERY(
SPLIT(REDUCE(,
BYROW(A2:S3,LAMBDA(row,JOIN("❄",row)))&"♥"&J2:J3-I2:I3+1,
LAMBDA(
acc,cur,
{acc;
IF(SEQUENCE(INDEX(SPLIT(cur,"♥",,),,2)),
INDEX(SPLIT(cur,"♥",,),,1))})),"❄",,),
"OFFSET 1",0)),
QUERY(
FLATTEN(MAP(I2:I3,J2:J3,LAMBDA(start,end,SEQUENCE(1,end-start+1,start)))),
"WHERE Col1 IS NOT NULL")},
"SELECT Col"&JOIN(", Col",SEQUENCE(COLUMN(J1)))&
", Col"&COLUMNS(A2:S3)+1&
", Col"&JOIN(", Col",SEQUENCE(COLUMNS(A2:S3)-COLUMN(J1),1,COLUMN(J1)+1))))
I have a Google spreadsheet with a tab called 'Updates'. In a separate tab, I want to use drop-down menus (contained in cells B3, B4 and B5 in the code below) to filter and subsequently view the data in the 'Updates' tab according to its text in columns B, C and D.
I have written the following code. Basically I want to be able to filter the data according to selections made in all 3 drop down menus (B3, B4 and B5), or just in two of them (e.g. B3 and B4, but B5 is left blank), or just in one of them (e.g. B3, and B4 and B5 are left blank).
=query(Updates!A1:E, " select * (where B = '"&B3&"' AND C = '"&B4&"' AND D = '"&B5&"') OR (where B = '"&B3&"' OR C = '"&B4&"' OR D = '"&B5&"') OR (where (B = '"&B3&"' OR C = '"&B4&"') AND D = '"&B5&"') OR (where B = '"&B3&"' AND (C = '"&B4&"' OR D = '"&B5&"') ) OR (where C = '"&B4&"' AND (B = '"&B3&"' OR D = '"&B5&"') ")
The AND and OR functions work separately in their own query functions, but when I combine them together I get the following error message:
Error
Unable to parse query string for Function QUERY parameter 2: PARSE_ERROR: Encountered " "(" "( "" at line 1, column 11. Was expecting one of: "where" ... "group" ... "pivot" ... "order" ... "skipping" ... "limit" ... "offset" ... "label" ... "format" ... "options" ...
Any help? Thanks!
you can use where only once in one QUERY. try:
=QUERY(Updates!A1:E,
"where 9=9 "&
IF(B3="",," and B = '"&B3&"'")&
IF(B4="",," and C = '"&B4&"'")&
IF(B5="",," and D = '"&B5&"'"), )
I have the left side of this screenshot, but need the right side. What are the formulas for columns D and E?
Use split() and the concatenation operator, like this:
=arrayformula(
query(
split(
flatten( A2:A & "→" & split(B2:B, ", ", true, true) ),
"→"
),
"where Col2 is not null", 0
)
)
I need to apply solution found in this question:
Using single formula to list unique items, count and sort numerically by descending order and then alphabetically for items with same count
This time adding a data validation menu for the search period.
I can do this for single cell but I'm not able to apply it to the solution above.
Formula for search period is this:
=COUNTIFS($B3:$B,"*apple*",$A3:$A,">="&TODAY()- VLOOKUP(
SUBSTITUTE(D2," ",""),
{"24HOURS",0;
"2DAYS",1;
"3DAYS",4;
"7DAYS",7;
"2WEEKS",14;
"1MONTH",30;
"3MONTHS",90;
"6MONTHS",180;
"1YEAR",365;
"2YEARS",730;
"3YEARS",1095;
"TOTAL",999999},
2,FALSE))
Formula taken from solution on question above:
=QUERY(B:B,"Select B, count(B) where B matches '^(?!(?:ITEMS|ExcludeB|ExcludeC)$).+' group by B order by count(B) DESC label count(B) ''")
Image to help clarify:
My dummy file:
https://docs.google.com/spreadsheets/d/1iB4BnqhTBVNuCCQ4GnEIu95gbzYb0T9H9A3Pi1W5AZk/edit?usp=sharing
Is such a thing possible? Any pointers on how this can be done? Thank you
In Excel (since you tagged it) you can use the following in Office 365:
=LET(a,A2:INDEX(B:B,LOOKUP(2,1/(A:A<>""),ROW(B:B))),
aa,INDEX(a,,1),
ab,INDEX(a,,2),
u,UNIQUE(INDEX(a,,2)),
c,COUNTIF(ab,u),
d,COUNTIFS(ab,u,
aa,">="&TODAY()
-VLOOKUP(SUBSTITUTE(D2," ",""),
{"24HOURS",0;
"2DAYS",1;
"3DAYS",4;
"7DAYS",7;
"2WEEKS",14;
"1MONTH",30;
"3MONTHS",90;
"6MONTHS",180;
"1YEAR",365;
"2YEARS",730;
"3YEARS",1095;
"TOTAL",999999},
2,0)),
SORT(CHOOSE({1,2,3},u,c,d),{2,1,1},{-1,1,1}))
This should do it.
=QUERY(
A:B,
"Select B, count(B)
where
B matches '^(?!(?:ITEMS|ExcludeB|ExcludeC)$).+' and
A >= date '"&
TEXT(
IFERROR(
VLOOKUP(
D2,
{"2 4 H O U R S",TODAY()-1;
"3 D A Y S",TODAY()-3;
"7 D A Y S",TODAY()-7;
"2 W E E K S",TODAY()-14;
"1 M O N T H",EDATE(TODAY(),-1);
"3 M O N T H S",EDATE(TODAY(),-3);
"6 M O N T H S",EDATE(TODAY(),-6);
"1 Y E A R",EDATE(TODAY(),-12);
"2 Y E A R S",EDATE(TODAY(),-24);
"3 Y E A R S",EDATE(TODAY(),-36)},
2,FALSE),0),"yyyy-mm-dd")&"'
group by B
order by
count(B) DESC,
B asc
label count(B) ''")
Using an array
=QUERY(
{A3:A,E3:E},
"Select Col2, count(Col2)
where
Col2 matches '^(?!(?:ITEMS|ExcludeB|ExcludeC)$).+' and
Col1 >= date '"&
TEXT(
IFERROR(
VLOOKUP(
G2,
{"2 4 H O U R S",TODAY()-1;
"3 D A Y S",TODAY()-3;
"7 D A Y S",TODAY()-7;
"2 W E E K S",TODAY()-14;
"1 M O N T H",EDATE(TODAY(),-1);
"3 M O N T H S",EDATE(TODAY(),-3);
"6 M O N T H S",EDATE(TODAY(),-6);
"1 Y E A R",EDATE(TODAY(),-12);
"2 Y E A R S",EDATE(TODAY(),-24);
"3 Y E A R S",EDATE(TODAY(),-36)},
2,FALSE),0),"yyyy-mm-dd")&"'
group by Col2
order by
count(Col2) DESC,
Col2 asc
label
Col2 '',
count(Col2) ''")
I have the following query which is working just fine.
but now I want to take the returned value in A which is a unique number and hyperlink it.
The resulting display should be just the number. The URL for the link is fixed with the number appended at the end e.g.
number = 123456
URL = https:\google.com\123456
my current query is:
=iferror(
if(C2="Closed",
QUERY(DATA!A:AA, "
SELECT A,B, D, T, N
WHERE( AA CONTAINS '" & lower(C1) & "' AND L = " & J1 & ")
Order by T Asc"),
QUERY(DATA!A:AA, "
SELECT A,B, D, R, N
WHERE( AA CONTAINS '" & lower(C1) & "' AND L = " & J1 & ")
Order by T Asc")
)
how can I manipulate the results of the query so each line returned the value in A is hyperlinked?
B8: =QUERY(B2:E5, "select C where E contains 'h11'", 0)
B14: =ARRAYFORMULA("www.abc.com/"&QUERY(B2:E5, "select C where E contains 'h11'", 0))