How do you create a “reverse pivot” in Google Sheets?

I wrote a simple general custom function, which is 100% reusable you can unpivot / reverse pivot a table of any size. In your case you could use it like this: =unpivot(A1:D4,1,1,”customer”,”sales”) So you can use it just like any built-in array function in spreadsheet. Please see here 2 examples: https://docs.google.com/spreadsheets/d/12TBoX2UI_Yu2MA2ZN3p9f-cZsySE4et1slwpgjZbSzw/edit#gid=422214765 The following is the … Read more

Convert matrix to 3-column table (‘reverse pivot’, ‘unpivot’, ‘flatten’, ‘normalize’)

To “reverse pivot”, “unpivot” or “flatten”: For Excel 2003: Activate any cell in your summary table and choose Data – PivotTable and PivotChart Report: For later versions access the Wizard with Alt+D, P. For Excel for Mac 2011, it’s ⌘+Alt+P (See here). Select Multiple consolidation ranges and click Next. In “Step 2a of 3”, choose … Read more

Equivalent to unpivot() in PostgreSQL

Create an example table: CREATE TEMP TABLE foo (id int, a text, b text, c text); INSERT INTO foo VALUES (1, ‘ant’, ‘cat’, ‘chimp’), (2, ‘grape’, ‘mint’, ‘basil’); You can ‘unpivot’ or ‘uncrosstab’ using UNION ALL: SELECT id, ‘a’ AS colname, a AS thing FROM foo UNION ALL SELECT id, ‘b’ AS colname, b AS … Read more

SQL Server : Columns to Rows

You can use the UNPIVOT function to convert the columns into rows: select id, entityId, indicatorname, indicatorvalue from yourtable unpivot ( indicatorvalue for indicatorname in (Indicator1, Indicator2, Indicator3) ) unpiv; Note, the datatypes of the columns you are unpivoting must be the same so you might have to convert the datatypes prior to applying the … Read more