Using GoogleSheet, I have two tables as input:
First table:
Name
val1
val2
val3
val4
Joe
X
X
X
Jess
X
X
X
Mark
X
X
meaning that Joe has val1 . val3 . val4, Jess has val1 . val2 . val4, Mark has val2 . val4
Second table is like a matrix:
| val1 | val2 | val3 | val4
val1 warn A warn B
val2 errA
val3
val4
identifying some couples of values associated with some text: val1.val3:warn A, val1.val4:warn B, val2.val3:err A
As result, I would like to join these two tables for extracting a table like this:
Name | Result
Joe warn B (val1.val4), warn A (val1.val3)
Jess warn A (val1.val4)
Mark
I need to address it using googlesheet but I fail, I have too many steps of transformation and finally I'm lost.
Currently, I though that using binary or operator could help. I proceed like this:
#1 Transform second table table2 in new dec values from base2 :
| val1 | val2 | val3 | val4
val1
10 9
val2 6
val3
val4
Each bit corresponds to Val[bit position]. ex : val1 => 1000 , val2 => 0100
(Val1, Val4) => BITOR(1000,0001) = 9
#2 same kind of transformation for the first table table1:
Name | val1(8) | val2(4) | val3(2) | val4(1)|
Joe 8 2 1
Jess 8 4 1
Mark 4 1
#3 extract relevant values form table2
=filter(transpose(flatten(table2)),transpose(flatten(table2))<>0)
I obtain : 10 | 9 | 6 (from table2)
#4 I sum rows in table1:
Name
sum
Joe
11
Jess
13
Mark
5
#5 I apply BITAND operator IF(BITAND(term2,term1)=term1,"Warn") between each terms from terms1 11 | 13 |5 and terms2 : 10 | 9 | 6
for Joe:
So as BITAND(11,10)=10 then i got a "Warn" for 1010 => (Val1,Val3)
So as BITAND(11,9)=9 then i got a "Warn" for 1001 => (Val1,Val4)
So as BITAND(11,6) not = 6 then nothing
But I implemented this for a small set of data as example and nothing is dynamic regarding the number of columns and rows... I guess if there a kind of function or query which could replace in a good way my poor code.
try:
=ARRAYFORMULA({A2:A5, REGEXREPLACE(TRIM(FLATTEN(QUERY(TRANSPOSE(
IF(REGEXMATCH(TRIM(FLATTEN(QUERY(TRANSPOSE(
IF(B2:E5="X", B1:E1, )),,9^9))), TRANSPOSE(QUERY(FLATTEN(
IF(B12:E16="",,A12:A16&".*"&B11:E11)),
"where Col1 is not null"))), TRANSPOSE(QUERY(FLATTEN(
IF(B12:E16="",,B12:E16&" ("&A12:A16&"."&B11:E11&"),")),
"where Col1 is not null")), )),,9^9))), ",$", )})
Related
I want to make the total of values every each member or names in every each their own group at the first match (or after blank space) or highest values positions of each them on column "D" according to column "B" with the result's row of an output like the exactly as an EXPECT OUTPUT as act of what I've just created on column "E". That's the replace a little bit down of just only one row from the column "B" positions or row must be the same as the column "C" and "D". Could we do this anyway ?
My achievements: I feel I've tried this before and got succeed to achieve this but I've forgot how to solve this when that happened. But it's look like kinda this code of formula:
=FILTER(IF(IFERROR(MATCH($B$3:$B;$B:$B;0);0)=ROW($B$3:$B);SUMIF($B$3:$B;$B$3:$B;$D$3:$D);"");$B$3:$B<>"0")
I don't know if I'm right or wrong but please see the table I'd created at the down below this and also see how I expected with that and feel free as well to edit to my doc file of google sheet I attached down below this.
THIS HERE YOU CAN EDIT TO MY SAMPLE G.SHEET TO SOLVE THIS MY QUIZ. THANKS IN ADVANCE!
A
B
C
D
E
1
2
N U M B
I D - M E M B E R
I D - C O D E
V A L U E S
E X P E C T O U T P U T
3
4
4
JYFI7
5
JYFI7
J3573
3
6
6
JYFI7
IYR
1
7
JYFI7
F498S
2
8
9
3
DFJ9F11
10
DFJ9F11
C684J
7
8
11
DFJ9F11
J58
1
12
13
2
H684K
14
H684K
JF585
2
2
15
16
1
FJSR
17
FJSR
4684
7
16
18
FJSR
834
1
19
FJSR
49
2
20
FJSR
9835
6
Here's a possible solution:
=ARRAYFORMULA(LAMBDA(cusum,IF(SCAN(,cusum,
LAMBDA(acc,cur,if(cur="",,acc+1)))=1,cusum,))
(SORT(SCAN(,SORT(D3:D,ROW(D3:D),0),
LAMBDA(acc,cur,if(cur="",,acc+cur))),ROW(D3:D),0)))
You can find it in tab 'z' cell F3.
I have a constant number X. I also have two numbers that add up to it. How can I make it so that if I change one number, the other number automatically changes so that it still adds up to X.
I have tried to take subtract the one number from X and add it to the other number, but instead I got two numbers in the thousands.
Assuming your constant value is 10, you can set this in a cell and make all your other calculations based on it.
For example, you can have cell C2 containing your constant, in this example, 10
Then in C4 you can have the number which you change, and the value of C5 will be equal to the value of the constant minus the value in C4.
You can then finally do your sum wherever you want, adding up the values of C4 and C5.
Here's an example Spreadsheet:
Untitiled spreadsheet ☆
File Edit View Insert Format Data Tools Extensions Help Last edit was 2 minutes ago
↶ ↷ 🖶 ⮷ | 100%⯆ | $ % .0 .00 123⯆ | Default(Ro... ⯆ | 10 ⯆ | B | I | S | A |⯐|☰
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
1
2
Contsant:
10
3
4
Number 1:
3
5
Number 2:
=(C2 - C4)
6
7
Sum:
=(C4 + C5)
8
Good Morning,
Sorry I am completely self taught so am probably missing something simple, I am trying to create a table based on values from other tables. I am not sure how to best explain what I want so here is the example;
Table1
Name Lname Issue1 Issue2 Issue3
Tom Smith 1234 1258 1175
Dick Scott 1258 1158 1852
Jane Davis 1234 1385 1111
Sarah Bennet 1158 1672 1234
Table2
Issue Desc
1234 A
1258 B
1175 C
1158 D
1852 E
1385 F
1111 G
1672 H
1468 I
Want
Name Lname Issue1 Desc1 Issue2 Desc2 Issue3 Desc3
Tom Smith 1234 A 1258 B 1175 C
Dick Scott 1258 B 1158 D 1852 E
Jane Davis 1234 A 1385 F 1111 G
Sarah Bennet 1158 D 1672 H 1234 A
I have done this previously by doing multiple joins to a single table but it seems like there should be a better way, here is what I am currently using
Proc SQL;
Select
a.Name
a.Lname
a.Issue1
b.Desc as Desc1
a.Issue2
c.Desc as Desc2
a.Issue3
d.Desc as Desc3
From work.Table1 a
Left Join work.Table2 b
on a.Issue1 eq b.Desc
Left Join work.Table2 c
on a.Issue2 eq c.Desc
Left Join work.Table2 d
on a.Issue3 eq d.Desc
So basically I want a table that has data from both but need multiple descriptions from Table 2 to match the issue values from table 1.
Thank you for your help!
You should transpose your data from wide to long, as e. g. in this example using PROC TRANSPOSE. It is often better to have data in the "long" format, e. g. to use BY-grouping in statistical procedures.
First sort the BY-variables.
proc sort data=have;
by Name Lname;
run;
Then transpose all variables Issue1-3.
proc transpose data=have out=want;
by Name Lname;
var Issue:;
run;
Then join with Table2.
Create a format from Table 2
Use an Array in a data step to create the new columns in Table 1 if required, or apply format.
data issue_fmt;
set table2;
start=issue;
label=desc;
fmtname='$Issue_fmt';
type='C';
run;
proc format cntlin=issue_fmt;
run;
*apply format;
proc print data=table1 (obs=10);
var issue1-issue3;
format issue1-issue3 $issue_fmt.;
run;
*create new variable with format;
data want;
set have;
array issues(*) issue1-issue200;
array desc(200) desc1-desc200;
do i=1 to dim(issues);
desc(i) = put(issues(i), $issue_fmt.);
end;
run;
In google sheets, I have a list of strings (1 per row) where each string is split with 1 character per column, so my sheet looks something like below:
A
B
C
D
E
F
1
F
R
A
N
K
2
P
A
S
S
1
2
I then have this sheet filtered, so Can select only the rows where the first character is F, for example. On another sheet in the same workbook, I have a table of how often each character appears in each column, that looks something like this:
A
B
C
D
E
F
1
Char
Overall
1
2
3
2
A
979
141
304
165
3
B
281
173
69
15
I would like to have this table dynamically update, so that when I filter the first sheet my table shows the frequency only for the strings that meet the filter.
In Excel, this can be accomplished using a combination of SUMPRODUCT and SUBTOTAL but this doesn't work in google sheets. I've seen this done in sheets using helper columns, but I would like the solution to work for a string of an arbitrary number of strings with different lengths without having to change the sheet. Can this be done in Google Sheets?
Thanks!
Hidden cells are assigned with the value 0. One way to solve this is by adding a "helper" column in column A and set all the values in it to 1.
| A | B | C | D | E | F | G
--+--------+------+---+---------+-----+-----+-----
1 | Helper | Char | | Overall | 1 | 2 | 3
--+--------+------+---+---------+-----+-----+-----
2 | 1 | A | | 979 | 141 | 304 | 165
3 | 1 | B | | 281 | 173 | 69 | 15
Now instead of using COUNTIF, use the COUNTIFS formula where the second condition A2:A = 1. For example:
=COUNTIFS([YOUR_CONDITION], A2:A,"=1")
the A column values of hidden rows will calculate as 0, therefore will not be counted.
I have table like this
A | B | C | Val
5 | 5 | 5 | 10
5 | 4 | 5 | 20
4 | 4 | 4 | 5
3 | 3 | 4 | 7
Is there any way sumifs can use criteria based on a set of numbers?
E.g. I want to sum the Val column based on these cells:
A: 5
B: 4,5 -> means get 4 or 5
C: 5
Then the result is 10 + 20 = 30
A: 3,4,5
B: 3,4
C: 4
Then the result is 5 + 7 = 12
You can combine SUMPRODUCT and MMULT functions to get dynamic formula:
=SUMPRODUCT(
($D$2:$D$5)
*MMULT(--($A$2:$A$5=$I$2:$K$2),ROW($A$1:$A$3)^0)
*MMULT(--($B$2:$B$5=$I$3:$K$3),ROW($A$1:$A$3)^0)
*MMULT(--($C$2:$C$5=$I$4:$K$4),ROW($A$1:$A$3)^0)
)
There's no simple way to do it with SUMIFS as it does not let you express OR conditions with Array literals like in Excel.
However, Google Sheets does offer the QUERY function.
Assume that criteria for A is in H1:1, B is in H2:2, C is in H3:3:
=QUERY(A:D,"select sum(D) where
(A="&TEXTJOIN(" or A=",1,H1:1)&") and
(B="&TEXTJOIN(" or B=",1,H2:2)&") and
(C="&TEXTJOIN(" or C=",1,H3:3)&")")
This gives you a header too. To get just the sum you can INDEX it:
=INDEX(
QUERY(A:D,"select sum(D) where
(A="&TEXTJOIN(" or A=",1,H1:1)&") and
(B="&TEXTJOIN(" or B=",1,H2:2)&") and
(C="&TEXTJOIN(" or C=",1,H3:3)&")")
,2)
With this, you don't have to worry about headers or the number of criteria.
For a way to do it without QUERY see #basic's solution.
I think you can do it with relatively simple SUMPRODUCT(MMULT(... as shown here on this sheet.
=SUMPRODUCT(E4:E,MMULT(N(REGEXMATCH(TO_TEXT(B4:D),B2:D2)),SEQUENCE(3,1,1,0))=3)
Note the use of the number 3 in two places which is indicative of how wide your data range is. It can be made dynamic, but it's easier to see how the formula works with the 3s as "hard" numbers for now.