This question already has answers here:
How do you create a "reverse pivot" in Google Sheets?
(10 answers)
Closed 5 months ago.
Background: Have a sheet that is being constantly updated with new rows, where the rows are in a PIVOTED fashion. Think left column is date, following columns are staff-ids - extending to right as new staff joins.
I have researched a bit - but did not find my required solution. Eg: the QUERY function has PIVOT but NO UNPIVOT function. So ...
Is there a FORMULA based method (without scripting) that can produce the normalized/UNPIVOTed data from the already pivoted data?
I'm not looking for a solution, hence no sample sheet. But rather, if this is possible, please point me to the functions that could do it ?
I don't know a formula that does this directly. What I would do is:
1) Use COUNT() twice, to count the columns and rows that contain data. Let's call these C and R.
2) Use simple formulas to write all combinations of C and R into C*R rows and 2 columns. Use more rows to allow for C and R to grow.
3) Use OFFSET() to read the pivoted data into the 3rd (unpivoted) column.
4) If you need to get rid of empty cells, use QUERY() on the 3 unpivoted columns.
Hope that helps.
Related
Attached is the link of my question
I would like to transpose the data like that.
My original data could be thousand of lines.
My thought is to make the same number of tables of my column title, then combine the four tables into one. My thought is on the google sheet as well. It might do the work but I would like a nicer solution.
A picture of my question
After having answered this question hundreds of times in the last couple years after the discovery of the FLATTEN() function, i decided to write a custom function for Google AppsScript to do it. While in some sense, a custom function is more opaque than the SPLIT(FLATTEN( formulaic solution you will find all over the forums in the last couple years, it is at least a little easier to understand in it's operation by the user.
In your shared sheet there is a new script file called MKHelp.gs. In it, you will find the code that I wrote to construct the "UNPIVOT()" function.
On a new tab in your sheet, you will find this formula in a tab called MK.Help.
=QUERY(UNPIVOT(A2:B,"V",C2:E,"B",C1:E1,"H"),"where Col3 is not null")
for unpivot to work well it is best surrounded by a query() to weed out unnecessary rows. In your case, it is that the "amount" not be "empty" or "null".
The letters "V","H" or "B" that follow each range describe the "shape" of the input data. Whether it is "vertical", "horizontal" or "Both".
Try
=query(arrayformula(split(flatten({(A3:A4&"♦"&B3:B4&"♦"&C3:E4)}),"♦")),"select * where Col3 is not null")
Explanation
step1: =arrayformula(A3:A4&"♦"&B3:B4&"♦"&C3:E4)
step2: =arrayformula(flatten(A3:A4&"♦"&B3:B4&"♦"&C3:E4)) , flatten will put all data inside one single column flatten()
step3: =query(arrayformula(split(flatten({(A3:A4&"♦"&B3:B4&"♦"&C3:E4)}),"♦")),"select * where Col3 is not null")
This question already has answers here:
Fill down - Google Apps Script for Spreadsheets
(4 answers)
Closed 4 years ago.
Hello right now I have a simple deposit / expense spreadsheet where I have a sum formula that does down column C adding(or subtracting) from what is put into column B. Formula is =SUM($B$1:B1) This works great for the rows that are created however when I add a new row. I have to drag down the forumula in C to cover the new row before it will calculate the new total. I would like this to be done automatically. IE I add a new row and it calculates C from what I entered in B and the history in C. Can't seem to find how to do this. Am using Google Spreadsheets so unsure if this is even possible.
This other question seems to be very complex coding for something else. My question was answered however by user JPV below. Thanks to him for his time.
Remove contents of column C and then try in C1 this formula
=ArrayFormula((IF(LEN(B1:B), SUMIF(ROW(B1:B),"<="&ROW(B1:B),B1:B),)))
I've been using Arrayformula to auto-expand formulas (such as "=Left(A2:A,B2:B-1") downward, but I need some help understanding this formula. I've read up on the function itself and browsed many forums about this but I can only find articles explaining how to use this with simple formulas, so I'm going to try to as this as simply as possible here: Is it possible to use Arrayformula to expand formulas downward when the formula uses arrays?
The summary for Arrayformula reads "Enables the display of values returned from an array formula into multiple rows and/or columns and the use of non-array functions with arrays." This was my understanding of how Arrayformula populated a formula into rows automatically. Using this I thought of it as writing a formula that generated an array of formulas, and then splitting them up with Arrayformula. This seems to not work with some formulas such as concatenate, which I will focus my question on. This example is far from my real life problem, but if someone could show me a solution I can apply it elsewhere.
Arrayformula spreadsheet example
Usually when I use Arrayformula with A1:A it would expand the formula through the column, referencing the corresponding rows as it went. With this example I want to have Column C be the concatenated result of columns A and B. Is this possible with Arrayformula? This question is not specific to concatenate, that is just the simplest one that came to mind. Another example would be Countif. Lets say I want to see how many values in the first 5 columns are over 20, and I want that formula to auto populate down, is that possible and if so how would it be done?
Arrayformula second example
P.S. Please don't say copy the formula using the drag handle in the lower right.
This question already has answers here:
How to do Vlookup using two search columns to compare with two result columns?
(2 answers)
Closed 1 year ago.
See my following spreadsheet: https://docs.google.com/spreadsheets/d/1SO3Z-liX1T61W47gKv5ugWFiQKsHa0-XBQsi1A7dTE0/edit?usp=sharing
I'm trying to create a formula that I can put into column C (the missing emails) based off of the names and emails in columns E-G.
In other words, I'm only missing the emails for folks to the left. The columns on the right has the data I need. I just need a formula that will auto-fill the missing emails based on matching the names in columns A/B and E/F.
I hope that makes sense. This is just an example spreadsheet. The real sheet I need to work with has hundreds of missing emails.
=ARRAYFORMULA(VLOOKUP(A2:A8&B2:B8,{E2:E14&F2:F14,G2:G14},2,0))
I've been working on a multi tiered drop down program, and in filtering one of the tables I stumbled upon a problem I can't find any help on.
Basically, I have 2 sheets. Sheet1!A2:A has a set of values. In this example, A2=110, A3=114, A4=162. However, with each use of the program, there could be any number of values and the values could change.
In the second sheet, Sheet2! there is a table. The first row has the headers that I want to return from my search. Under each header is a series of numbers ranging from 3 to well over 50 values. And the number of columns is also unknown...(it will keep getting larger).
So I want to know which columns have all 3 values from Sheet1!A2:A in them.
Column 3 might have 6 numbers (95,110,114,125,150,162) and column 7 might have (80,110,114,125) so I would want to return the header from Column 3 but not from column 7.
Does any of this make sense? Again in simple terms, I want to query all of the columns in Sheet2 to see which contain all of the values from Sheet1!A2:A
Any help would be so greatly appreciated...
-Daniel
I set up an sheet using your example data:
https://docs.google.com/spreadsheets/d/169VrbWkTlRMzhNPe4G8hQL1MdfqQuTvjb87aRD9hiWo/edit#gid=1923440782
I've restricted the formula in cell D2 to 500 rows for the sake of speed but you can remove the references to make it work across the whole sheet:
=FILTER(Sheet2!1:1,ArrayFormula(TRANSPOSE(mmult(TRANSPOSE(COUNTIF(A2:A500,Sheet2!A2:Z500)),TRANSPOSE(split(rept("1,",COLUMNS(TRANSPOSE(COUNTIF(A2:A500,Sheet2!A2:Z500)))),",")))=count(A2:A500))))