How to do a vlookup for each result found by regexreplace? - google-sheets

I have a Google sheet cell A1 with markdown like this:
Param | Value | Units
--- | --- | ---
**K1** | [PS1\Geral_K1] |ºC
**K2** | [PS1\Geral_K2] |ºC
**K3** | [PS1\Geral_K3] |ºC
All if this is on the same cell, A1.
PS1\Geral_K? is a param to be fetched from another sheet.
So I need to extract the string inside [] and make a vlookup to get the valor for this param.
I already have this code to check I get the result for each group found.
=REGEXREPLACE(A1,"\[([^]]+)\]","$1")
Now I want to use "$1" to vlookup in another table for each of the following
PS1\Geral_K1
PS1\Geral_K2
PS1\Geral_K3
how can I do it ???
This is the result I want to have in B1
Param | Value | Units
--- | --- | ---
**K1** | 100 |ºC
**K2** | 20 |ºC
**K3** | 30 |ºC

paste in D2 and drag down:
=IFERROR(ARRAYFORMULA(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(
QUERY(QUERY({Campos!A:A, Campos!B:B&"♣"&Campos!D:D&"♠"},
"select Col2 where Col1 = '"&A2&"'"), , 999^99),
" ", CHAR(10)), "♣", " "), "♠", " °C")))

Related

Count all element occurences in list in cell(by list I mean a string with seperators) in google docs

I have two tables
Table 1:
| list_of_ids |
1 | 1; 2 |
2 | 3 |
3 | 4; 5; 1 |
Table 2:
| id | count |
1 | 1 | 2 |
2 | 2 | 1 |
3 | 4 | 1 |
4 | 6 | 0 |
how do I automatically fill in count?
I currently have a very unsatisfying and hacky way of doing it like this:
list_of_ids is formatted like ;id;id;id; instead of id; id; id
count =COUNTIF(range, "*"&";"&id_cell&";"&"*")
is there a way to do it more properly, so to not force users to write ids in such a way?
try:
=INDEX(QUERY(FLATTEN(SPLIT(TEXTJOIN(";"; 1; A:A); ";"));
"select Col1,count(Col1)
where Col1 is not null
group by Col1
label count(Col1)''"))
or:
=ARRAYFORMULA(IF(C2:C="";;IFNA(VLOOKUP(C2:C;
QUERY(FLATTEN(SPLIT(TEXTJOIN(";"; 1; A:A); ";"));
"select Col1,count(Col1)
where Col1 is not null
group by Col1
label count(Col1)''"); 2; 0); 0)))

gSheets: How to use SPLIT in ARRAYFORMULA over columns

For numbers x and y, I have cell data formatted as x#y.
An example row:
| A | B | C | D |
| ------ | ------ | ----- | ------ |
|10#100 | 10#120 | 8#150 | 5#175 |
I want to parse this type of row into two quantities: the sum of the x's and sum of y's.
With my example, I should have two cells:
33 and 545
Basically, I want to SUM the resulting array of SPLIT applied to each cell in A1:D1.
My attempt
=SUM(ARRAYFORMULA(SPLIT(A1:D1, "#")))
Unfortunately, this approach doesn't allow me to specify whether I want x or y (when I call SPLIT) and it seems to be returning x + y, rather than sum(i=1 to 4) x_i.
Try this:
=index(query(arrayformula(split(transpose(A1:D1), "#")),"select sum(Col1),sum(Col2) ",0),2)
Another option:
=ArrayFormula({SUM(INDEX(SPLIT(TRANSPOSE(A1:D1),"#"),0,1)),SUM(INDEX(SPLIT(TRANSPOSE(A1:D1),"#"),0,2))})
use:
=SUMPRODUCT(SPLIT(JOIN("#",A1:D1),"#"),ISEVEN(SEQUENCE(1,COUNTA(A1:D1)*2)-1))
F3= (replace ISEVEN -> ISODD)
use:
=ARRAYFORMULA(QUERY(QUERY(SPLIT(TRANSPOSE(A1:D1); "#");
"sum(Col1),sum(Col2)"); "offset 1"; 0))

How to get all values (of particular column) of a lookup value in a single cell?

I have headers (dptype, day, batchtimings).how to get multiple (day and batch-timings values) of an individual lookup value in a single cell of another sheet?
Example:
Dp type | day |batchtimings
---------|-------------|----------------
a | Saturday | 10-11
b | friday | 11-12
a | monday | 01-02
y | tuesday | 02-03
b | sunday | 04-05
a | wednesday | 04-07
c | sunday | 03-04
a | friday | 10-12
v | monday | 10-11
b | thursday | 11-12
y | monday | 09-10
I want individual dptype's all the day and batch timings values in a single cell (unique)
I want-example:
dp type batches
------------------------------
| Saturday:10-11
a | monday :1-2
| wednesday:4-7
| friday:10-12
--------|--------------------
b | friday:11-12
| Sunday:4-5
| thursday:11-12
--------|--------------------
y | tuesday:2-3
| monday:9-10
Get your list of Unique Types:
=UNIQUE(A2:A12)
Then reference those with:
=join(char(10),UNIQUE(FILTER(B:B&":"&text(C:C,"mm-dd"),A:A=F1)))
You can try
=IFNA( JOIN (" :"), FILTER(B1:C10, A1:A10="A"))
Where you would replace the value at the end with what your looking for
use:
=ARRAYFORMULA({SORT(UNIQUE(FILTER(A2:A, A2:A<>""))), TRANSPOSE(SUBSTITUTE(TRIM(
QUERY(QUERY(QUERY(UNIQUE({A2:C, B2:B&":"&TO_TEXT(C2:C)}),
"select max(Col4) where Col1 is not null group by Col2 pivot Col1"),
"offset 1", 0),,999^99)), " ", CHAR(10)))})

How to import data that has a value from other sheets

I have 2 spreadsheets and I'm trying to get all the items that the QTY is not equal to zero.
Can someone help me, please?
Example. If the items in Spreadsheet 1 is not 0 it will transfer to Spreadsheet 2 in one cell.
Spreadsheet 1
*---*----*---*----*
| | ITEMS | QTY|
*---*--------*----*
| 1 | BOOK | 4 |
| 2 | PEN | 4 |
| 3 | tape | 0 |
*---*----*--------*
Spreadsheet 2
+---+---------+
| | A |
+---+---------+
| 1 | BOOK 4 |
| | PEN 4 |
+---+---------+
This formula is the formula.
=JOIN(CHAR(10),QUERY(TRANSPOSE(IMPORTRANGE("URL","SUMMARY!B1:C3")),,2000000))
=TEXTJOIN(CHAR(10), 1, TRANSPOSE(QUERY(TRANSPOSE(QUERY(IMPORTRANGE(
"ID", "Sheet1!A:B"),
"where not Col2 = 0 and Col1 is not null", 0)), , 999^99)))

How to translate COUNTIFS formula in ARRAYFORMULA to automatically insert the formula in each row

With my countifs formula in column C I want to auto-number (running total) all occurrences of an identical string in column A (e.g. Apple or Orange) but only if on the same row where the string appears column B is of a certain type, e.g. if in column B the type is of "fruit" in column C auto number all occurrences of an identical string in column A. For each new string which is of type "fruit" start the numbering all over again.
The outcome should be like this:
+---+-----------+-------+---+--+
| | A | B | C | |
+---+-----------+-------+---+--+
| 1 | Apple | Fruit | 1 | |
| 2 | Apple | Fruit | 2 | |
| 3 | Mercedes | Car | 0 | |
| 4 | Mercedes | Car | 0 | |
| 5 | Orange | Fruit | 1 | |
| 6 | Orange | Fruit | 2 | |
| 7 | Apple | Fruit | 3 | |
+---+-----------+-------+---+--+
The formula in column C:
=COUNTIFS($A1:$A$1;A1;$B1:$B$1;"Fruit")
=COUNTIFS($A$1:$A2;A2;$B$1:$B2;"Fruit")
=COUNTIFS($A$1:$A3;A3;$A$1:$A3;"Fruit")
…and so on…
I want to translate this formula into an array formula and put this into the header so the formula will automatically expand.
No matter what I've tried it won't work.
Any help is truly appreciated!
Here's a link to a sheet: [https://docs.google.com/spreadsheets/d/1lgbuLbTSnyKkqr33NdVuDEv5eoXFwatX1rgeF9YpIks/edit?usp=sharing][1]
={"ARRAYFORMULA HERE"; ARRAYFORMULA(IF(LEN(B2:B), IF(B2:B="Fruit",
MMULT(N(ROW(B2:B)>=TRANSPOSE(ROW(B2:B))), N(B2:B="Fruit"))-
HLOOKUP(0, MMULT(N(ROW(B2:B)>TRANSPOSE(ROW(B2:B))), N(B2:B="Fruit")),
MATCH(VLOOKUP(ROW(B2:B), IF(N(B2:B<>B1:B), ROW(B2:B), ), 1, 1),
VLOOKUP(ROW(B2:B), IF(N(B2:B<>B1:B), ROW(B2:B), ), 1, 1), 0), 0), 0), ))}
demo spreadsheet
=ARRAYFORMULA(IF(LEN(B2:B), IF(B2:B="Fruit",
MMULT(N(ROW(B2:B)>=TRANSPOSE(ROW(B2:B))), N(B2:B="Fruit")), 0), ))

Resources