{"id":2988,"date":"2016-11-03T19:27:50","date_gmt":"2016-11-03T19:27:50","guid":{"rendered":"http:\/\/wiki.davelevy.info\/?p=2988"},"modified":"2016-11-04T11:35:20","modified_gmt":"2016-11-04T11:35:20","slug":"how-to-unpivot-in-excel","status":"publish","type":"post","link":"https:\/\/davelevy.info\/wiki\/how-to-unpivot-in-excel\/","title":{"rendered":"How to unpivot in Excel"},"content":{"rendered":"<p>The need to unpivot data is a common requirement. There are a number of reasons as to why. I and my customers are primarily using\u00a0 Excel on Windows and so the examples below are shown in excel and rely on excel functionality.<!--more--><\/p>\n<p>I use the Pivot table wizard and integrated drill down. A second technique is available using power query, but this is an addon until Excel 2016.<\/p>\n<h3>Using the Pivot Wizard<\/h3>\n<p>Here is my test data table.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2989\" src=\"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-data-1-w450.png\" alt=\"unp-data-1-w450\" width=\"450\" height=\"409\" srcset=\"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-data-1-w450.png 450w, https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-data-1-w450-300x273.png 300w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\" \/><\/p>\n<p>Use the key combination <code>[Alt] + [D]<\/code>, then <code>[P]<\/code>, this opens the pivot table wizard.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2990\" src=\"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-wiz-1-w450.png\" alt=\"unp-wiz-1-w450\" width=\"450\" height=\"336\" srcset=\"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-wiz-1-w450.png 450w, https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-wiz-1-w450-300x224.png 300w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\" \/><\/p>\n<p>Select the Multiple Consolidation Ranges radio button<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2991\" src=\"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-wiz-2-w450.png\" alt=\"unp-wiz-2-w450\" width=\"450\" height=\"338\" srcset=\"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-wiz-2-w450.png 450w, https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-wiz-2-w450-300x225.png 300w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\" \/><\/p>\n<p>and then <code>[Next]<\/code>. Select the I will create page fields radio button<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2992\" src=\"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-wiz-3-w450.png\" alt=\"unp-wiz-3-w450\" width=\"450\" height=\"326\" srcset=\"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-wiz-3-w450.png 450w, https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-wiz-3-w450-300x217.png 300w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\" \/><\/p>\n<p>and then <code>[Next]<\/code>. Set the data range and then press the <code>[Add]<\/code> button<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2993\" src=\"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-wiz-4-w600.png\" alt=\"unp-wiz-4-w600\" width=\"600\" height=\"376\" srcset=\"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-wiz-4-w600.png 600w, https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-wiz-4-w600-300x188.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>and then <code>[Next]<\/code>. Set the location of the new pivot table.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2994\" src=\"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-wiz-5-w450.png\" alt=\"unp-wiz-5-w450\" width=\"450\" height=\"306\" srcset=\"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-wiz-5-w450.png 450w, https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-wiz-5-w450-300x204.png 300w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\" \/><\/p>\n<p>and then <code>[Finish]<\/code>. The new pivot table is created.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2995\" src=\"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-data-2-w600.png\" alt=\"unp-data-2-w600\" width=\"600\" height=\"159\" srcset=\"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-data-2-w600.png 600w, https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-data-2-w600-300x80.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>Double click on the Grand Total\/Grand Total field.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2996\" src=\"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-data-3-w600.png\" alt=\"unp-data-3-w600\" width=\"600\" height=\"145\" srcset=\"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-data-3-w600.png 600w, https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-data-3-w600-300x73.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>A full drill down is created in a new worksheet<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2997\" src=\"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-data-4-w600.png\" alt=\"unp-data-4-w600\" width=\"240\" height=\"399\" srcset=\"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-data-4-w600.png 240w, https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2016\/11\/unp-data-4-w600-180x300.png 180w\" sizes=\"auto, (max-width: 240px) 100vw, 240px\" \/><\/p>\n<p>This is not dynamic, changes in the original data table will not be reflected in the new TNF table. The drill down will need to be repeated.<\/p>\n<p>I was guided by <a href=\"http:\/\/stackoverflow.com\/questions\/20541905\/convert-matrix-to-3-column-table-reverse-pivot-unpivot-flatten-normal\">this page<\/a>. My example has a value range ( a,b,c, null) in the original matrix cells.<\/p>\n<p style=\"text-align: center;\">ooOOOoo<\/p>\n<h3>Using Power Query<\/h3>\n<p>I used this video as a guide for using <a href=\"https:\/\/support.office.com\/en-gb\/article\/Introduction-to-Microsoft-Power-Query-for-Excel-6e92e2f4-2079-4e1f-bad5-89f6269cd605\">Power Query<\/a> to perform the work.<\/p>\n<p><iframe loading=\"lazy\" title=\"Excel Magic Trick 1292: Power Query Unpivot into Proper Lookup Table to Score Myers-Briggs Test\" width=\"1099\" height=\"618\" src=\"https:\/\/www.youtube.com\/embed\/0WBgD0l5r-4?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen><\/iframe><\/p>\n<p>and <a title=\"Excel Magic Trick 1338: Power Query: Unpivot 12 Cross Tabulated Tables into One Proper Data Set \" href=\"https:\/\/www.youtube.com\/watch?v=bJ0tr50BzhA\">this one<\/a>, was my initial guide, I got lost in the add additional column part of the script, but this is probably important part of the answer.<\/p>\n<blockquote><p>The huge advantage of this technique is that the results are dynamic; if you change the source, then the output changes to reflect new inputs.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>The need to unpivot data is a common requirement. There are a number of reasons as to why. I and my customers are primarily using\u00a0 Excel on Windows and so the examples below are shown in excel and rely on excel functionality.<\/p>\n","protected":false},"author":1,"featured_media":2678,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","_share_on_mastodon":"0"},"categories":[27,3],"tags":[156,920,911,1071,236],"class_list":["post-2988","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","category-technology","tag-excel","tag-software","tag-technology","tag-unpivot","tag-wizard"],"share_on_mastodon":{"url":"","error":""},"jetpack_featured_media_url":"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2015\/05\/excel-175sq.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts\/2988","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/comments?post=2988"}],"version-history":[{"count":1,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts\/2988\/revisions"}],"predecessor-version":[{"id":3002,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts\/2988\/revisions\/3002"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/media\/2678"}],"wp:attachment":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/media?parent=2988"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/categories?post=2988"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/tags?post=2988"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}