Partial transpose of Sheet - google-sheets

I have a Google Sheet with this format:
+---------+---------+---------+------------+------------+------------+------------+--------+--------+
| Field_A | Field_B | Field_C | 24/09/2019 | 25/09/2019 | 26/09/2019 | 27/09/2019 | day... | day... |
+---------+---------+---------+------------+------------+------------+------------+--------+--------+
| ValX | ValY | ValZ | Val1 | Val2 | Val3 | Val4 | | |
| ValW | ValY | ValZ | Val5 | Val6 | Val7 | Val8 | | |
+---------+---------+---------+------------+------------+------------+------------+--------+--------+
First 3 columns are specific fields and all other columns are related to one specific day in a given (and static) range.
I need to convert the table in the following format:
+---------+---------+---------+------------+-----------+
| Field_A | Field_B | Field_C | Date | DateValue |
+---------+---------+---------+------------+-----------+
| ValX | Valy | Valz | 24/09/2019 | Val1 |
| ValX | Valy | Valz | 25/09/2019 | Val2 |
| ValX | Valy | Valz | 26/09/2019 | Val3 |
| ... | | | | |
+---------+---------+---------+------------+-----------+
Basically, the first 3 columns are gathered as-is, but the day-column in transposed (is even the correct term?) with 2 values:
The date
The value in the cell related to date
Is something that can be achieved with formula or do I need to create a bounded AppsScript?
Following a sample Sheet demo: https://docs.google.com/spreadsheets/d/1cprzD96i-4NQ8tieA_nwd8s43yKF-M8Kww4yWNfB6tg/edit#gid=505040170
In Sheet Start you can see the initial data and format, 3 static columns and one column for every da
In Sheet End you can see the output format I'm looking for, the same 3 static columns, but the date and cell value related to date are transposed as a row.
You can see the Formula I used, TRANSPOSE for every row, where I select the days for the IV column and one row at a time for the V row.
For the 3 static columns, I replicated the Formula for every instance of the day related to that row.
This is working but requires much manual work to set up every single TRANSPOSE. I'm wondering if there is a more automatic way of doing this (except for using AppsScript, in that case, I'm already planning on doing this if not other solutions are available)

=ARRAYFORMULA(TRIM(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(Start!D2:F<>""; "♦"&TRANSPOSE(QUERY(TRANSPOSE(Start!A2:C&"♠");;999^99))&
TEXT(Start!D1:F1; "dd/mm/yyyy")&"♠"&Start!D2:F; ));;999^99));;999^99); "♦")); "♠")))

Related

Find multiple matches in a dataset, and return all matches in a single row

What array formula would work for this?
Test Sheet: Open
Current Data Structure
Contains a running list of names and when they started, ended training.
| A | B | C |
| John | StartDate1 | EndDate1 |
| Adam | StartDate3 | EndDate3 |
| John | StartDate2 | EndDate2 |
| Ted | StartDate5 | EndDate5 |
| Adam | StartDate4 | EndDate4 |
Expected Results
Unique column of names in column E =UNIQUE(A2:A)
Next to the unique name, display every StartDate & EndDate that matches the unique name.
| E | F | G | H | I |
| John | StartDate1 | EndDate1 | StartDate2 | EndDate2 |
| Adam | StartDate3 | EndDate3 | StartDate4 | EndDate4 |
| Ted | StartDate4 | EndDate4 | | |
What I have tried
=FILTER(B2:C,A2:A = E2)
Does not return on a single row. ❌
Does not work with ARRAYFORMULA. ❌
=TRANSPOSE(FILTER(B2:C,A2:A = E2:E))
Returns all StartDates on a single row, and all End Dates on the next row. ❌
It should return on a single row (StartDate,EndDate,StartDate,EndDate, etc)
Does not work with ARRAYFORMULA. ❌
=ARRAYFORMULA(VLOOKUP(E2:E,A2:C,{2,3}))
Returns the first match only ❌
Works with array formula. ✔️
What am I doing wrong? Is there a better arrayformula that can display every start and end date that matches a unique name in a row?
Thanks for your help!
use:
=INDEX(SPLIT(FLATTEN(QUERY(QUERY(IF(A3:A="",,{A3:A, "×"&B3:B&"×"&C3:C}),
"select max(Col2) where Col2 is not null group by Col2 pivot Col1"),,9^9)), "×"))

Find (and return) range of cells containing formulae

I am working on a table where I track down a Meter value on daily basis.
Since it's not really daily updated, I use a formula to forecast the Meter value.
Therefore the forecasted trend between the (variable) days of a manual input is not 100% reliable and made a formula where # m³ was calculated only if not ISFORMULA(B#) (see below), in order to read in column m³ the real usage between those days.
BUT now I came to the idea to autopopulate the m³ cells between the range with an auto-calculated daily average between the days where two values have been inserted manually.
So i came up with this draft version for column C
for C11 =if(isformula(B11),if(isblank(C12),,if(isformula(B12),C12,"RANGE_DIFF/DAYS")),RANGE_DIFF)
where, in this case, RANGE_DIFF should beB12-B9 and DAYS = 3
In other words, how do I determine and return the range of cells between two manually inserted values?
Link to sheet
Thanks in advance :)
+----------+-----------+----------+
| Date | Meter | m³ |
+----------+-----------+----------+
| ... | ... | ... |
| 09/1 | 9,381.296 | 0.75 m³ | <<< MANUAL INSERTION | =IF(ISFORMULA(C9),,C9-C8)
| 10/1 | 9,382.622 | | <<< =TREND(B3:B9,A3:A9,A10) | * =C11
| 11/1 | 9,383.955 | | <<< =TREND(B4:B10,A4:A10,A11) | * =RANGE_DIFF/DAYS
| 12/1 | 9,385.197 | ??? | <<< MANUAL INSERTION | *** RANGE_DIFF >>> =B12-B9
| 13/1 | 9,386.350 | 1.15 m³ | <<< MANUAL INSERTION | =IF(ISFORMULA(C13),,C13-C12)
| ... | ... | ... |
+----------+-----------+----------+

Get whole row by two unique fields in a Google Sheet

I have tried to achieve this for the last few hours with no luck so I am appealing for help.
I have a google form which saves to a google spreadsheet and the responses are recording in a structure as per below.
---------------------------------------------------------
| WEEK | CATEGORY | COL1 | COL2 | TIMESTAMP |
|--------|------------|---------|----------|--------------|
| 1 | CAT1 | VALUE1 | VALUE1 | YYYY-MM-DD |
| 1 | CAT1 | VALUE2 | VALUE2 | YYYY-MM-DD |
| 1 | CAT2 | VALUE1 | VALUE1 | YYYY-MM-DD |
| 2 | CAT3 | VALUE1 | VALUE1 | YYYY-MM-DD |
| 2 | CAT3 | VALUE2 | VALUE2 | YYYY-MM-DD |
---------------------------------------------------------
I need a formula which I can use in google sheets to take the most recent entry where WEEK and CATEGORY together are unique values.
Eg using the above table, the formula would result in something that looks like this.
---------------------------------------------------------
| WEEK | CATEGORY | COL1 | COL2 | TIMESTAMP |
|--------|------------|---------|----------|--------------|
| 1 | CAT1 | VALUE2 | VALUE2 | YYYY-MM-DD |
| 1 | CAT2 | VALUE1 | VALUE1 | YYYY-MM-DD |
| 2 | CAT3 | VALUE2 | VALUE2 | YYYY-MM-DD |
---------------------------------------------------------
Any help would be greatly appreciated!
Thanks,
There isn't a super clean solution for what is basically a dynamic self-join in SQL parlance, but this might be manageable:
Get a list of maximum timestamps per category and week
Filter the original table by this derived list using a concatenated key
Any attempts to improve this answer appreciated (in particular the string concatenation as key is not very elegant).

Try to match string in column and print matching column name

I am trying to build an expense dashboard in google sheets for my personal use.
I have data that I will pull from my receipts like so:
First sheet: "Expenses Feb 18"
+------------+--------+--------+
| Item | Amount | Type |
+------------+--------+--------+
| Tomatoes | 2.39 | veggie |
| Joghurt | 1.45 | dairy |
| mozzarella | 1.99 | dairy |
| macadamia | 4.59 | nuts |
+------------+--------+--------+
Second table: "Categories"
+------------+----------+-----------+---------------+
| dairy | veggie | nuts | uncategorised |
+------------+----------+-----------+---------------+
| joghurt | tomatoes | macadamia | a |
| mozzarella | cucumber | pecan | b |
| feta | | | c |
| | | | d-z |
| | | | 0-9 |
| | | | - |
| | | | _ |
+------------+----------+-----------+---------------+
I want to automatically fill out the type column based on the item name.
So far I have a regex that is able to match an item. It will print the matched string. But what I need is the column name (header). And it has to be able to loop through the columns. This only works for a single column.
=REGEXEXTRACT(C11, JOIN("|", INDIRECT("Categories!A1:A"&COUNTA(Categories!A:A))))
The second table is not a desirable way to enter data. Data should be entered preferably with more rows than columns ( not in a pivoted manner).
=ARRAYFORMULA(CONCATENATE(IF(A16=$C$24:$E$25,C$23:E$23,)))
A16 : 🍅
C24:E25: Category table
C23:E23: Category header.

Returning ArrayFormula from multiple sheets, in the same cell

I have two Google sheets with different Marvel characters (column A) and their corresponding home universe (column C).
Sheet1
| Heroes | Count | Universe |
|:------------------|--------------:|:------------------:|
| Spider Ham | 365 | Earth-8311 |
| Iron Man | 467 | Earth-616 |
| Hulk Bunny | 24 | Earth-8311 |
Sheet2
| Heroes | Count | Universe |
|:------------------|--------------:|:------------------:|
| Spider Ham | 234 | Earth-8311 |
| Iron Man | 998 | Earth-616 |
| May Porker | 11 | Earth-8311 |
In Sheet3 this formula in each row =ArrayFormula(TEXTJOIN(", ";1;REPT(Sheet1!A:A;1*(Sheet1!C:C=A$2)))) (placed in column B) grabs the data from Sheet1 and return in like this:
| Universe | Heroes |
|:-----------------|------------------------------------:|
| Earth-8311 | Spider Ham, Hulk Bunny |
| Earth-616 | Iron Man |
Which is great. But I also want combine the data from Sheet2 in the formula - so Sheet3 looks like this (without duplicates):
| Universe | Heroes |
|:-----------------|------------------------------------:|
| Earth-8311 | Spider Ham, Hulk Bunny, May Porker |
| Earth-616 | Iron Man |
I want to modify the ArrayFormula to search in Sheet1 AND Sheet2 - is this possible to do in a single Spreadsheet-formula?
Tried =ArrayFormula(TEXTJOIN(", ";1;REPT(Sheet1:Sheet2!A:A;1*(Sheet1Sheet2!C:C=A$2)))) but it only returns #NAME?
Please try:
=ArrayFormula(TEXTJOIN(", ",1,UNIQUE(filter({Sheet1!A:A;Sheet2!A:A},{Sheet1!C:C;Sheet2!C:C}=A2))))
Used arrays {} in Google Sheets, and filter formula. Unique is to get rid of duplicates.

Resources