I have a tabular report, also called a matrix or "crosstab". For example, the name of the customer is indicated in the column headers, the name of the product in the row headers and the number of products sold to each customer in the intersection.
+---+------------+-----------+-----------+-------- ---+ | | To | B | C | D | +---+------------+-----------+-----------+-------- ---+ | 1 | | Client 1 | Client 2 | Client 3 | | 2 | Product 1 | 4 | 2 | 6 | | 3 | Product 2 | 7 | 8 | 6 | | 4 | Product 3 | 6 | 3 | 5 | | 5 | Product 4 | 3 | 3 | 8 | +---+------------+-----------+-----------+-------- ---+
I require to pass the data to plain table format, i.e. one column for row headers, one column for column headers and one column for values, as shown below:
+----+---------------------+---------------------- --+-----+ | | To | B | C | +----+---------------------+---------------------- --+-----+ | 1 | Row Headers | Column headers | Values | | 2 | Product 1 | Client 1 | 4 | | 3 | Product 2 | Client 2 | 8 | | 4 | Product 3 | Client 3 | 5 | | 5 | Product 4 | Client 1 | 3 | | 6 | Product 1 | Client 2 | 2 | | 7 | Product 2 | Client 3 | 6 | | 8 | Product 3 | Client 1 | 6 | | 9 | Product 4 | Client 2 | 3 | | 10 | Product 1 | Client 3 | 6 | | 11 | Product 2 | Client 1 | 7 | | 12 | Product 3 | Client 2 | 3 | | 13 | Product 4 | Client 3 | 8 | +----+---------------------+---------------------- --+-----+
How can I achieve this using google spreadsheet functions?
Clarifications
Question inspired by How do you create a “reverse pivot” in Google Sheets? - Stack Overflow and personal experience.
In this file you will find an example of how to perform the conversion. The steps to follow are described below.
data
, that cell A1 is blank and that it does not include data from outside the report.A1:
=COUNTA(data!A:A)
Number of rows.A2:
=COUNTA(data!1:1)
Number of columns.A3:
=CELL("address",data!A1)
Intermediate calculation.A4:
=LEFT(A3,FIND("!",A3)-1)
Name of the sheet with the source data.A1: Row Headers
A2:
B1: Column
headers B2:
C1: Values
C2:
Description of the constructs used
ROW(INDIRECT("A1:A"&Aux!A1*Aux!A2))
determines an array of consecutive numbers whose size corresponds to the number of rows required in the final result.MOD(ROW(INDIRECT("A1:A"&Aux!A1*Aux!A2))-1,Aux!A1)+1
determines the index of the row header.MOD(ROW(INDIRECT("A1:A"&Aux!A1*Aux!A2))-1,Aux!A2)+1
determines the index of the column header.{(ROW(INDIRECT("A1:A"&Aux!A1+1))),INDIRECT(Aux!A4&"!R1C1:R"&Aux!A1+1&"C"&Aux!A2+1,false)}
creates a matrix whose first column is the index of the row and the following corresponds to the data of the tabular report.I have put together a solution to your problem with google apps script that I think is simpler than the one proposed so far.
In the code editor of the sheet put the following:
Save the code file. Every time someone modifies the "Original" sheet, the "Destination" sheet will be updated.
Hope this can help you.
I found the question very interesting from a didactic point of view, so I used it to publish on my blog... I hope you don't mind: http://googleappscriptsweb.blogspot.com.es/2016/06/como- convert-a-data-array-to.html
I had the same problem but I found a solution that I already applied with a script. Here comes everything how to do it and I give the respective credit to Viktor Camp
I suggest you see the link and there it takes you to the example and everything is very well explained
All are reasonable solutions, in my case I had a data table with 19 columns and 1600 rows and the "unpivot" tool of the HdCPlus plugin worked very well, which is open source and has other interesting utilities. https://workspace.google.com/marketplace/app/hdc+/410659432888