{"id":7138,"date":"2014-03-05T00:00:03","date_gmt":"2014-03-05T00:00:03","guid":{"rendered":"http:\/\/craftydba.com\/?p=7138"},"modified":"2016-04-19T20:29:49","modified_gmt":"2016-04-19T20:29:49","slug":"power-query-part-3","status":"publish","type":"post","link":"https:\/\/craftydba.com\/?p=7138","title":{"rendered":"Power Query &#8211; Part 3"},"content":{"rendered":"<p>There has been a big push for self service business intelligence tools by Microsoft in recent months.  The center of this universe is Microsoft Excel.  <\/p>\n<p>I will keep on going with talks about Power Query which is a self service ETL add-in for MS Excel. This tool was <a href=\"http:\/\/blogs.msdn.com\/b\/powerbi\/archive\/2013\/08\/29\/try-the-latest-power-query-update.aspx\">released <\/a>in August of 2013. In addition to my blog, the <a href=\"http:\/\/office.microsoft.com\/en-us\/excel-help\/microsoft-power-query-for-excel-help-HA104003813.aspx\">online help<\/a> is a good place to start learning about this tool.<\/p>\n<p>Last time, I demonstrated how the &#8220;get external data&#8221; and &#8220;excel data&#8221; ribbon buttons can be used to export the source data into the Query editor.  Also, we saw how Power Query is very flexible given the large number of import options.  <\/p>\n<p>Today, I am going to start flushing out the various operations in the Query Editor that can be used to refine our data.<\/p>\n<p>We first need to open the &#8220;Postal Codes&#8221; workbook query by selecting the edit option.  The following ribbon will show on top of the data.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C01-power-query-toolbar-ribbon.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C01-power-query-toolbar-ribbon-1024x107.jpg\" alt=\"C01-power-query-toolbar-ribbon\" width=\"665\" height=\"69\" class=\"aligncenter size-large wp-image-7143\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C01-power-query-toolbar-ribbon-1024x107.jpg 1024w, https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C01-power-query-toolbar-ribbon-300x31.jpg 300w, https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C01-power-query-toolbar-ribbon.jpg 1101w\" sizes=\"auto, (max-width: 665px) 100vw, 665px\" \/><\/a><\/p>\n<p>I am going to concentrate on the &#8220;reduce&#8221; operations.  These operations reduce the number of columns or rows in the resulting data set.<\/p>\n<p>The &#8220;remove top rows&#8221; operation can be used to delete rows from the top of the data set.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C02-power-query-remove-top-n-rows.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C02-power-query-remove-top-n-rows.jpg\" alt=\"C02-power-query-remove-top-n-rows\" width=\"875\" height=\"441\" class=\"aligncenter size-full wp-image-7145\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C02-power-query-remove-top-n-rows.jpg 875w, https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C02-power-query-remove-top-n-rows-300x151.jpg 300w\" sizes=\"auto, (max-width: 875px) 100vw, 875px\" \/><\/a><\/p>\n<p>The &#8220;remove columns&#8221; operation has two choices.  Either we can remove a highlighted column or we can remove all columns except for highlighted one.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C03-power-query-remove-columns.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C03-power-query-remove-columns.jpg\" alt=\"C03-power-query-remove-columns\" width=\"578\" height=\"334\" class=\"aligncenter size-full wp-image-7148\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C03-power-query-remove-columns.jpg 578w, https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C03-power-query-remove-columns-300x173.jpg 300w\" sizes=\"auto, (max-width: 578px) 100vw, 578px\" \/><\/a><\/p>\n<p>The next operation is kind-of interesting since I can not image a real life usage case.  The &#8220;remove alternating rows&#8221; operation starts at row A and removes B rows and keeps C rows in a alternating pattern.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C04-power-query-reduceremove-alternate-rows-1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C04-power-query-reduceremove-alternate-rows-1.jpg\" alt=\"C04-power-query-reduce~remove-alternate-rows-1\" width=\"702\" height=\"310\" class=\"aligncenter size-full wp-image-7152\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C04-power-query-reduceremove-alternate-rows-1.jpg 702w, https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C04-power-query-reduceremove-alternate-rows-1-300x132.jpg 300w\" sizes=\"auto, (max-width: 702px) 100vw, 702px\" \/><\/a><\/p>\n<p>If we apply these choices to the postal codes data set, the following information is left over.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C05-power-query-reduceremove-alternate-rows-output-2.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C05-power-query-reduceremove-alternate-rows-output-2.jpg\" alt=\"C05-power-query-reduce~remove-alternate-rows-output-2\" width=\"580\" height=\"339\" class=\"aligncenter size-full wp-image-7155\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C05-power-query-reduceremove-alternate-rows-output-2.jpg 580w, https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C05-power-query-reduceremove-alternate-rows-output-2-300x175.jpg 300w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/a><\/p>\n<p>I am avoiding the &#8220;remove errors&#8221; operation since the easiest way to create an error is to change the target data type.  Most data coming into Power Query defaults as a text data type.  We will cover this operation when I show you how to change data types in the &#8220;transform&#8221; section of the ribbon.<\/p>\n<p>Also, I am purposely skipping the &#8220;remove duplicates&#8221; operation.  I will demonstrate this operation when I cover the &#8220;combine&#8221; section of the ribbon.  I will be able to double the data after we cover the &#8220;append&#8221; operation under that section.<\/p>\n<p>The &#8220;keep top rows&#8221; operation allows the user to remove rows at the end of the data set.  Only the top most N rows will be keep.<\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C08-power-query-reducekeep-top-rows.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C08-power-query-reducekeep-top-rows.jpg\" alt=\"C08-power-query-reduce~keep-top-rows\" width=\"702\" height=\"252\" class=\"aligncenter size-full wp-image-7157\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C08-power-query-reducekeep-top-rows.jpg 702w, https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C08-power-query-reducekeep-top-rows-300x107.jpg 300w\" sizes=\"auto, (max-width: 702px) 100vw, 702px\" \/><\/a><\/p>\n<p>To round off row operators, the &#8220;keep range&#8221; button allows you to slice out a range of rows.  <\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C09-power-query-reducekeep-range.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C09-power-query-reducekeep-range.jpg\" alt=\"C09-power-query-reduce~keep-range\" width=\"702\" height=\"265\" class=\"aligncenter size-full wp-image-7158\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C09-power-query-reducekeep-range.jpg 702w, https:\/\/craftydba.com\/wp-content\/uploads\/2014\/03\/C09-power-query-reducekeep-range-300x113.jpg 300w\" sizes=\"auto, (max-width: 702px) 100vw, 702px\" \/><\/a><\/p>\n<p>Just like the RIGHT, LEFT and MID string functions, I consider the REMOVE TOP, KEEP TOP, and KEEP RANGE operators as similar purposed functions that operate on rows of data.<\/p>\n<p>In a nutshell, the Power Query tool supplies the user with tools to reduce the number of rows and\/or columns in the source data set.  Thus, cleaning up the raw data before being analyzed in the Power Pivot, Power View or Power Map tools.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There has been a big push for self service business intelligence tools by Microsoft in recent months. The center of this universe is Microsoft Excel. I will keep on going with talks about Power Query which is a self service ETL add-in for MS Excel. This tool was released in August of 2013. In addition to my blog, the online help is a good place to start learning about this tool. Last time, I demonstrated how the &#8220;get external data&#8221; and &#8220;excel data&#8221; ribbon buttons can be used to export&hellip;<\/p>\n","protected":false},"author":1,"featured_media":7070,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1042],"tags":[15,1062,1061,1043,1055,1057,1060,1059,1058,1045],"class_list":["post-7138","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-power-query","tag-john-f-miner-iii","tag-keep-range","tag-keep-top-rows","tag-power-query","tag-query-editor","tag-reduce-operations","tag-remove-alternating-rows","tag-remove-columns","tag-remove-top-rows","tag-self-service-etl"],"_links":{"self":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/7138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7138"}],"version-history":[{"count":0,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/7138\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/media\/7070"}],"wp:attachment":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}