<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:georss="http://www.georss.org/georss"
xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
><channel><title>Power Query &#8211; DataVeld</title> <atom:link href="http://dataveld.com/category/power-query/feed/" rel="self" type="application/rss+xml" /><link>https://dataveld.com</link> <description>A Microsoft Data Experience Blog</description> <lastBuildDate>Sat, 28 Jul 2018 01:48:55 +0000</lastBuildDate> <language>en-US</language> <sy:updatePeriod> hourly </sy:updatePeriod> <sy:updateFrequency> 1 </sy:updateFrequency> <generator>https://wordpress.org/?v=5.3.21</generator><image> <url>https://i0.wp.com/dataveld.com/wp-content/uploads/2016/10/cropped-cropped-dataveld23.png?fit=32%2C32&#038;ssl=1</url><title>Power Query &#8211; DataVeld</title><link>https://dataveld.com</link> <width>32</width> <height>32</height> </image> <site
xmlns="com-wordpress:feed-additions:1">143031883</site> <item><title>Geocoding in a Pinch: Power Query and the Google Maps API</title><link>https://dataveld.com/2015/08/24/geocoding-in-a-pinch-power-query-and-the-google-maps-api/</link> <comments>https://dataveld.com/2015/08/24/geocoding-in-a-pinch-power-query-and-the-google-maps-api/#respond</comments> <pubDate>Mon, 24 Aug 2015 08:35:06 +0000</pubDate> <dc:creator><![CDATA[David Eldersveld]]></dc:creator> <category><![CDATA[Power BI]]></category> <category><![CDATA[Power Query]]></category> <category><![CDATA[M]]></category><guid
isPermaLink="false">https://olddataveld.wordpress.com/?p=110</guid> <description><![CDATA[<p><span
class="rt-reading-time" style="display: block;"><span
class="rt-label rt-prefix">Reading Time: </span> <span
class="rt-time">4</span> <span
class="rt-label rt-postfix">minutes</span></span> A colleague of mine recently asked if I knew of an easy way to get latitude and longitude coordinates from city and state information.  Of course I do!  There are plenty of ways, and many of the best ones involve...</p><p>The post <a
rel="nofollow" href="https://dataveld.com/2015/08/24/geocoding-in-a-pinch-power-query-and-the-google-maps-api/">Geocoding in a Pinch: Power Query and the Google Maps API</a> appeared first on <a
rel="nofollow" href="https://dataveld.com">DataVeld</a>.</p> ]]></description> <content:encoded><![CDATA[<span
class="rt-reading-time" style="display: block;"><span
class="rt-label rt-prefix">Reading Time: </span> <span
class="rt-time">4</span> <span
class="rt-label rt-postfix">minutes</span></span><p>A colleague of mine recently asked if I knew of an easy way to get latitude and longitude coordinates from city and state information.  Of course I do!  There are plenty of ways, and many of the best ones involve a service like Melissa Data and less development work.  For little effort and usually a price, you can obtain a reference table for cities or tables for zip codes or census tracts that include latitude and longitude alongside the primary city at that grain.  For the ambitious though, you can access an API and geocode your data using a variety of common languages.  It can even be done with M in Power Query.</p><p>Depending on the use case, an API may or may not be a good fit.  Weighing different methods is not in the scope of this post though.  I simply want to pass along a quick way to geocode data from city/state or address/city/state using Power Query for a handful of records.  To do this, I&#8217;ll connect to the Google Maps API because the address information is passed as a parameter in the URL.  As an added benefit, the code also provides an example of how to retrieve values using JSON.</p><p>NOTA BENE: The method outlined here is not meant for large scale operations&#8211;hence I want to emphasize that this post&#8217;s title states &#8220;in a pinch&#8221;.  The free version of the <a
href="https://developers.google.com/maps/documentation/geocoding/intro" target="_blank" rel="noopener">Google Maps API</a> only allows 2,500 requests in a 24 hour period and restricts requests to 5 per second.</p><p>In addition to the limitations of the free tier Google Maps API, there are some additional performance considerations, so <em>plan ahead</em>.  API calls can be costly, so avoid unnecessary requests.  For example, consider your grain.  If you have 10,000 individual addresses that are all in the same city&#8211;but you only want the coordinates for the city center point&#8211;you can make <em>one</em> request instead of <em>ten thousand</em>.  In cases like this, it would be inefficient to use the original table due to the many addresses located in the same city.  The better method here would be to build a separate table with distinct city values first, make API requests for the records in that city table, then join back to the original table.  Plan ahead!</p><p>Now for some M&#8230;</p><ol><li>Start with your source.  Out of convenience, I am using a small table in Excel that contains two separate columns for city and state.  Remember that you are not limited to this grain&#8211;you could work with individual addresses too.  Load the source data into Power Query.<br
/> <a
href="http://dataveld.files.wordpress.com/2015/08/pq-geocodesource.png?resize=459%2C158"><img
data-attachment-id="120" data-permalink="https://dataveld.com/pq-geocodesource/" data-orig-file="https://i2.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-geocodesource.png?fit=459%2C158&amp;ssl=1" data-orig-size="459,158" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="PQ-GeocodeSource" data-image-description="&lt;p&gt;Power Query Geocode Source&lt;/p&gt;
" data-medium-file="https://i2.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-geocodesource.png?fit=300%2C103&amp;ssl=1" data-large-file="https://i2.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-geocodesource.png?fit=459%2C158&amp;ssl=1" class="aligncenter wp-image-120 size-full" src="http://dataveld.files.wordpress.com/2015/08/pq-geocodesource.png?resize=459%2C158" alt="Power Query Geocode Source" width="459" height="158" srcset="https://i2.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-geocodesource.png?w=459&amp;ssl=1 459w, https://i2.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-geocodesource.png?resize=300%2C103&amp;ssl=1 300w" sizes="(max-width: 459px) 100vw, 459px" data-recalc-dims="1" /></a></li><li>The method (one method&#8230;) used to access Google Maps involves appending an address parameter value to the end of the base URL.  You do not need to worry about URL encoding for spaces or commas: <strong>http://maps.googleapis.com/maps/api/geocode/json?address=SampleAddress</strong></li><li>Add a new column in Power Query that appends the city and state column to the base URL. <strong><br
/> <a
href="http://dataveld.files.wordpress.com/2015/08/pq-geocodebuildurl.png?resize=640%2C175"><img
data-attachment-id="121" data-permalink="https://dataveld.com/pq-geocodebuildurl/" data-orig-file="https://i2.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-geocodebuildurl.png?fit=863%2C235&amp;ssl=1" data-orig-size="863,235" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="PQ-GeocodeBuildURL" data-image-description="&lt;p&gt;Power Query Geocode Build URL&lt;/p&gt;
" data-medium-file="https://i2.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-geocodebuildurl.png?fit=300%2C82&amp;ssl=1" data-large-file="https://i2.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-geocodebuildurl.png?fit=640%2C174&amp;ssl=1" class="aligncenter size-full wp-image-121" src="http://dataveld.files.wordpress.com/2015/08/pq-geocodebuildurl.png?resize=640%2C175" alt="Power Query Geocode Build URL" width="640" height="175" srcset="https://i2.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-geocodebuildurl.png?w=863&amp;ssl=1 863w, https://i2.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-geocodebuildurl.png?resize=300%2C82&amp;ssl=1 300w, https://i2.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-geocodebuildurl.png?resize=768%2C209&amp;ssl=1 768w" sizes="(max-width: 640px) 100vw, 640px" data-recalc-dims="1" /></a></strong></li><li>At this stage, I am ready to send my web request.  Because the response from the web request will be JSON, I need to wrap my Web.Contents() function with Json.Document() instead of Web.Page().<br
/> <a
href="http://dataveld.files.wordpress.com/2015/08/pq-geocodejsonsource.png?resize=640%2C128"><img
data-attachment-id="122" data-permalink="https://dataveld.com/pq-geocodejsonsource/" data-orig-file="https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-geocodejsonsource.png?fit=808%2C161&amp;ssl=1" data-orig-size="808,161" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="PQ-GeocodeJsonSource" data-image-description="&lt;p&gt;Power Query JSON source&lt;/p&gt;
" data-medium-file="https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-geocodejsonsource.png?fit=300%2C60&amp;ssl=1" data-large-file="https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-geocodejsonsource.png?fit=640%2C128&amp;ssl=1" class="aligncenter size-full wp-image-122" src="http://dataveld.files.wordpress.com/2015/08/pq-geocodejsonsource.png?resize=640%2C128" alt="Power Query JSON source" width="640" height="128" srcset="https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-geocodejsonsource.png?w=808&amp;ssl=1 808w, https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-geocodejsonsource.png?resize=300%2C60&amp;ssl=1 300w, https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-geocodejsonsource.png?resize=768%2C153&amp;ssl=1 768w" sizes="(max-width: 640px) 100vw, 640px" data-recalc-dims="1" /></a></li><li>The latitude and longitude are deeply nested in the JSON, but I can click into the first record using the UI to find the path down to both values.  At this point, Power Query has generated a lot of M code that shows how to get the data that I need.  The problem with clicking through the UI is that it only gets me the coordinates for the first location.<br
/> <a
href="http://dataveld.files.wordpress.com/2015/08/pq-geocodejsonclicks.png?resize=210%2C74"><img
data-attachment-id="123" data-permalink="https://dataveld.com/pq-geocodejsonclicks/" data-orig-file="https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-geocodejsonclicks.png?fit=210%2C74&amp;ssl=1" data-orig-size="210,74" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="PQ-GeocodeJsonClicks" data-image-description="&lt;p&gt;Power Query JSON clicks&lt;/p&gt;
" data-medium-file="https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-geocodejsonclicks.png?fit=210%2C74&amp;ssl=1" data-large-file="https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-geocodejsonclicks.png?fit=210%2C74&amp;ssl=1" class="aligncenter size-full wp-image-123" src="http://dataveld.files.wordpress.com/2015/08/pq-geocodejsonclicks.png?resize=210%2C74" alt="Power Query JSON clicks" width="210" height="74" data-recalc-dims="1" /></a></li><li>I can use this structure as a start though, condense that into one line, and remove the extra code. In this case, the formula for latitude appears below.  Note that &#8220;<strong>GetJson{0}</strong>&#8221; from the first record has been replaced with &#8220;<strong>each GetJson{_}</strong>&#8221; to enumerate.<br
/> <a
href="http://dataveld.files.wordpress.com/2015/08/pq-geocodejsoncondensed.png?resize=640%2C146"><img
data-attachment-id="124" data-permalink="https://dataveld.com/pq-geocodejsoncondensed/" data-orig-file="https://i0.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-geocodejsoncondensed.png?fit=715%2C164&amp;ssl=1" data-orig-size="715,164" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="PQ-GeocodeJsonCondensed" data-image-description="&lt;p&gt;Power Query JSON condensed&lt;/p&gt;
" data-medium-file="https://i0.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-geocodejsoncondensed.png?fit=300%2C69&amp;ssl=1" data-large-file="https://i0.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-geocodejsoncondensed.png?fit=640%2C147&amp;ssl=1" class="aligncenter size-full wp-image-124" src="http://dataveld.files.wordpress.com/2015/08/pq-geocodejsoncondensed.png?resize=640%2C146" alt="Power Query JSON condensed" width="640" height="146" srcset="https://i0.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-geocodejsoncondensed.png?w=715&amp;ssl=1 715w, https://i0.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-geocodejsoncondensed.png?resize=300%2C69&amp;ssl=1 300w" sizes="(max-width: 640px) 100vw, 640px" data-recalc-dims="1" /></a></li><li>Add a second column using the same procedure for longitude, and I&#8217;m done!  Here&#8217;s the full code:</li></ol><pre>let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    BuildUrl = Table.AddColumn(Source, "Custom", each "http://maps.googleapis.com/maps/api/geocode/json?address=" &amp; [City]  &amp; "," &amp; [State]),
    RenameUrlColumn = Table.RenameColumns(BuildUrl,{{"Custom", "GoogleMapsGeocodeURL"}}),
    GetJson = Table.AddColumn(RenameUrlColumn, "JsonDoc", each Json.Document(Web.Contents([GoogleMapsGeocodeURL]))),

    Latitude = Table.AddColumn(GetJson, "Latitude", each GetJson{_}[JsonDoc][results]{0}[geometry][location][lat]),
    Longitude = Table.AddColumn(Latitude, "Longitude", each Latitude{_}[JsonDoc][results]{0}[geometry][location][lng])
in
    Longitude</pre><p>While it&#8217;s not the best method available, it is straightforward to geocode data for a quick lookup using Power Query.  Given a small list of cities and states, I have the data, and it took less than five minutes!  For requirements in the range of a handful to a few hundred records, that&#8217;s a great time saver. Simply remember the limitations of the free API, and do not forget to plan ahead!</p><p>&nbsp;</p><p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?6bfec1&amp;6bfec1"></script><br
/> <br
/> <ins
class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-5931835938684253"
data-ad-slot="6104236328"
data-ad-format="auto"></ins><br
/><script>(adsbygoogle=window.adsbygoogle||[]).push({});</script></p><p>The post <a
rel="nofollow" href="https://dataveld.com/2015/08/24/geocoding-in-a-pinch-power-query-and-the-google-maps-api/">Geocoding in a Pinch: Power Query and the Google Maps API</a> appeared first on <a
rel="nofollow" href="https://dataveld.com">DataVeld</a>.</p> ]]></content:encoded> <wfw:commentRss>https://dataveld.com/2015/08/24/geocoding-in-a-pinch-power-query-and-the-google-maps-api/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <post-id
xmlns="com-wordpress:feed-additions:1">110</post-id> </item> <item><title>Step by Step: Using Power Query to Replace Text in Table Headers</title><link>https://dataveld.com/2015/08/08/step-by-step-using-power-query-to-replace-text-in-table-headers/</link> <comments>https://dataveld.com/2015/08/08/step-by-step-using-power-query-to-replace-text-in-table-headers/#comments</comments> <pubDate>Sat, 08 Aug 2015 16:13:13 +0000</pubDate> <dc:creator><![CDATA[David Eldersveld]]></dc:creator> <category><![CDATA[Power BI]]></category> <category><![CDATA[Power Query]]></category> <category><![CDATA[M]]></category><guid
isPermaLink="false">https://olddataveld.wordpress.com/?p=69</guid> <description><![CDATA[<p><span
class="rt-reading-time" style="display: block;"><span
class="rt-label rt-prefix">Reading Time: </span> <span
class="rt-time">4</span> <span
class="rt-label rt-postfix">minutes</span></span> Recently, I came across a dataset involving traffic accidents that I really liked and wanted to clean up for a demonstration.  As with most datasets originally pulled from the web or from text files, there were various issues before it...</p><p>The post <a
rel="nofollow" href="https://dataveld.com/2015/08/08/step-by-step-using-power-query-to-replace-text-in-table-headers/">Step by Step: Using Power Query to Replace Text in Table Headers</a> appeared first on <a
rel="nofollow" href="https://dataveld.com">DataVeld</a>.</p> ]]></description> <content:encoded><![CDATA[<span
class="rt-reading-time" style="display: block;"><span
class="rt-label rt-prefix">Reading Time: </span> <span
class="rt-time">4</span> <span
class="rt-label rt-postfix">minutes</span></span><p>Recently, I came across a dataset involving traffic accidents that I really liked and wanted to clean up for a demonstration.  As with most datasets originally pulled from the web or from text files, there were various issues before it could be used.  Some items would have prevented the type of analysis that I wanted.  These included having units stored with potential measures, i.e. &#8220;70 miles per hour&#8221; instead of 70.  Other changes were preferred more out of convenience, such as the desire to remove spaces from the column headers.</p><p>While I have used Power Query for a number of projects, I had only previously replaced text in table records using Table.ReplaceValue() and various Text functions.  These functions do not operate on headers directly.  As an aside, I rue the lack of M support for regular expressions every time I replace text in Power Query.  In any case, I wanted to document a way to change text in table headers only.  Here is a walkthrough of my M query:</p><ol><li>Load the source data into Power Query.  Note the ultimate target of elimination&#8211;the space in the column headers.<br
/> <a
href="http://dataveld.files.wordpress.com/2015/08/pq-ch-source.png?resize=400%2C74"><img
data-attachment-id="73" data-permalink="https://dataveld.com/pq-ch-source/" data-orig-file="https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-source.png?fit=400%2C74&amp;ssl=1" data-orig-size="400,74" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="PQ-CH-Source" data-image-description="" data-medium-file="https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-source.png?fit=300%2C56&amp;ssl=1" data-large-file="https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-source.png?fit=400%2C74&amp;ssl=1" class="aligncenter size-full wp-image-73" src="http://dataveld.files.wordpress.com/2015/08/pq-ch-source.png?resize=400%2C74" alt="PQ-CH-Source" width="400" height="74" srcset="https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-source.png?w=400&amp;ssl=1 400w, https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-source.png?resize=300%2C56&amp;ssl=1 300w" sizes="(max-width: 400px) 100vw, 400px" data-recalc-dims="1" /></a></li><li>Demote the headers.<br
/> <a
href="http://dataveld.files.wordpress.com/2015/08/pq-ch-demoteheaders.png?resize=400%2C75"><img
data-attachment-id="75" data-permalink="https://dataveld.com/pq-ch-demoteheaders/" data-orig-file="https://i0.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-demoteheaders.png?fit=400%2C75&amp;ssl=1" data-orig-size="400,75" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="PQ-CH-DemoteHeaders" data-image-description="" data-medium-file="https://i0.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-demoteheaders.png?fit=300%2C56&amp;ssl=1" data-large-file="https://i0.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-demoteheaders.png?fit=400%2C75&amp;ssl=1" class="aligncenter size-full wp-image-75" src="http://dataveld.files.wordpress.com/2015/08/pq-ch-demoteheaders.png?resize=400%2C75" alt="PQ-CH-DemoteHeaders" width="400" height="75" srcset="https://i0.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-demoteheaders.png?w=400&amp;ssl=1 400w, https://i0.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-demoteheaders.png?resize=300%2C56&amp;ssl=1 300w" sizes="(max-width: 400px) 100vw, 400px" data-recalc-dims="1" /></a></li><li>At this point, there is a choice.  Many people may choose to transpose the table now and put the column headers into Column1.  This would be followed by a Table.ReplaceValue function to remove the whitespace and another transpose to put the column headers back.  On a particularly wide table, this route also happens to lead to an Out of Memory Exception.  Sometimes transposing an entire table with tens of thousands of records or more as well as 53 columns is a <em>really bad idea</em>.  Trust me.<a
href="http://dataveld.files.wordpress.com/2015/08/pq-outofmemory.png?resize=456%2C195"><img
data-attachment-id="77" data-permalink="https://dataveld.com/pq-outofmemory/" data-orig-file="https://i0.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-outofmemory.png?fit=456%2C195&amp;ssl=1" data-orig-size="456,195" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="PQ-OutOfMemory" data-image-description="" data-medium-file="https://i0.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-outofmemory.png?fit=300%2C128&amp;ssl=1" data-large-file="https://i0.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-outofmemory.png?fit=456%2C195&amp;ssl=1" class="aligncenter wp-image-77 size-full" style="border:1px solid #000000;" src="http://dataveld.files.wordpress.com/2015/08/pq-outofmemory.png?resize=456%2C195" alt="PQ-OutOfMemory" width="456" height="195" srcset="https://i0.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-outofmemory.png?w=456&amp;ssl=1 456w, https://i0.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-outofmemory.png?resize=300%2C128&amp;ssl=1 300w" sizes="(max-width: 456px) 100vw, 456px" data-recalc-dims="1" /></a></li><li>Pending some magical M function that I am (hopefully) missing, what is a better route?  Instead of transposing the entire table, transpose <em>only the row of headers that is needed</em>.  To get there, create a copy of the original table.  While not ideal, it is a refreshing alternative to an out of memory exception.  In the Advanced Editor, simply add a new step referencing the previous one, i.e &#8220;HeaderTable = DemoteHeaders&#8221;.<br
/> <a
href="http://dataveld.files.wordpress.com/2015/08/pq-ch-headertable.png?resize=423%2C61"><img
data-attachment-id="79" data-permalink="https://dataveld.com/pq-ch-headertable/" data-orig-file="https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-headertable.png?fit=423%2C61&amp;ssl=1" data-orig-size="423,61" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="PQ-CH-HeaderTable" data-image-description="" data-medium-file="https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-headertable.png?fit=300%2C43&amp;ssl=1" data-large-file="https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-headertable.png?fit=423%2C61&amp;ssl=1" class="aligncenter size-full wp-image-79" src="http://dataveld.files.wordpress.com/2015/08/pq-ch-headertable.png?resize=423%2C61" alt="PQ-CH-HeaderTable" width="423" height="61" srcset="https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-headertable.png?w=423&amp;ssl=1 423w, https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-headertable.png?resize=300%2C43&amp;ssl=1 300w" sizes="(max-width: 423px) 100vw, 423px" data-recalc-dims="1" /></a></li><li>Next, keep only the target row of headers in the new table using the Table.FirstN() function.<br
/> <a
href="http://dataveld.files.wordpress.com/2015/08/pq-ch-headerfirstrow.png?resize=191%2C31"><img
data-attachment-id="82" data-permalink="https://dataveld.com/pq-ch-headerfirstrow/" data-orig-file="https://i0.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-headerfirstrow.png?fit=191%2C31&amp;ssl=1" data-orig-size="191,31" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="PQ-CH-HeaderFirstRow" data-image-description="" data-medium-file="https://i0.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-headerfirstrow.png?fit=191%2C31&amp;ssl=1" data-large-file="https://i0.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-headerfirstrow.png?fit=191%2C31&amp;ssl=1" class="aligncenter size-full wp-image-82" src="http://dataveld.files.wordpress.com/2015/08/pq-ch-headerfirstrow.png?resize=191%2C31" alt="PQ-CH-HeaderFirstRow" width="191" height="31" data-recalc-dims="1" /></a></li><li>The header row is now ready to be transposed using the Table.Transpose() function.<br
/> <a
href="http://dataveld.files.wordpress.com/2015/08/pq-ch-transpose.png?resize=336%2C128"><img
data-attachment-id="88" data-permalink="https://dataveld.com/pq-ch-transpose/" data-orig-file="https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-transpose.png?fit=336%2C128&amp;ssl=1" data-orig-size="336,128" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="PQ-CH-Transpose" data-image-description="" data-medium-file="https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-transpose.png?fit=300%2C114&amp;ssl=1" data-large-file="https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-transpose.png?fit=336%2C128&amp;ssl=1" class="aligncenter size-full wp-image-88" src="http://dataveld.files.wordpress.com/2015/08/pq-ch-transpose.png?resize=336%2C128" alt="PQ-CH-Transpose" width="336" height="128" srcset="https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-transpose.png?w=336&amp;ssl=1 336w, https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-transpose.png?resize=300%2C114&amp;ssl=1 300w" sizes="(max-width: 336px) 100vw, 336px" data-recalc-dims="1" /></a></li><li>Here is the key step where the whitespace disappears using the Table.ReplaceValue() function.<br
/> <a
href="http://dataveld.files.wordpress.com/2015/08/pq-ch-replace.png?resize=609%2C124"><img
data-attachment-id="90" data-permalink="https://dataveld.com/pq-ch-replace/" data-orig-file="https://i0.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-replace.png?fit=609%2C124&amp;ssl=1" data-orig-size="609,124" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="PQ-CH-Replace" data-image-description="" data-medium-file="https://i0.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-replace.png?fit=300%2C61&amp;ssl=1" data-large-file="https://i0.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-replace.png?fit=609%2C124&amp;ssl=1" class="aligncenter size-full wp-image-90" src="http://dataveld.files.wordpress.com/2015/08/pq-ch-replace.png?resize=609%2C124" alt="PQ-CH-Replace" width="609" height="124" srcset="https://i0.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-replace.png?w=609&amp;ssl=1 609w, https://i0.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-replace.png?resize=300%2C61&amp;ssl=1 300w" sizes="(max-width: 609px) 100vw, 609px" data-recalc-dims="1" /></a></li><li>Once the whitespace has been removed, transpose the table again to restore the headers as a row.<br
/> <a
href="http://dataveld.files.wordpress.com/2015/08/pq-ch-transposeback.png?resize=403%2C75"><img
data-attachment-id="92" data-permalink="https://dataveld.com/pq-ch-transposeback/" data-orig-file="https://i2.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-transposeback.png?fit=403%2C75&amp;ssl=1" data-orig-size="403,75" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="PQ-CH-TransposeBack" data-image-description="" data-medium-file="https://i2.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-transposeback.png?fit=300%2C56&amp;ssl=1" data-large-file="https://i2.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-transposeback.png?fit=403%2C75&amp;ssl=1" class="aligncenter size-full wp-image-92" src="http://dataveld.files.wordpress.com/2015/08/pq-ch-transposeback.png?resize=403%2C75" alt="PQ-CH-TransposeBack" width="403" height="75" srcset="https://i2.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-transposeback.png?w=403&amp;ssl=1 403w, https://i2.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-transposeback.png?resize=300%2C56&amp;ssl=1 300w" sizes="(max-width: 403px) 100vw, 403px" data-recalc-dims="1" /></a></li><li>At this point, the table with the single header row needs to be combined with the original table.<br
/> <a
href="http://dataveld.files.wordpress.com/2015/08/pq-ch-combinetables.png?resize=490%2C122"><img
data-attachment-id="94" data-permalink="https://dataveld.com/pq-ch-combinetables/" data-orig-file="https://i2.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-combinetables.png?fit=490%2C122&amp;ssl=1" data-orig-size="490,122" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="PQ-CH-CombineTables" data-image-description="" data-medium-file="https://i2.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-combinetables.png?fit=300%2C75&amp;ssl=1" data-large-file="https://i2.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-combinetables.png?fit=490%2C122&amp;ssl=1" class="aligncenter size-full wp-image-94" src="http://dataveld.files.wordpress.com/2015/08/pq-ch-combinetables.png?resize=490%2C122" alt="PQ-CH-CombineTables" width="490" height="122" srcset="https://i2.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-combinetables.png?w=490&amp;ssl=1 490w, https://i2.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-combinetables.png?resize=300%2C75&amp;ssl=1 300w" sizes="(max-width: 490px) 100vw, 490px" data-recalc-dims="1" /></a></li><li>Once the tables are combined, you can see the altered headers <em>and</em> the original headers.  To remove the duplicate header, promote the first row to headers using the Table.PromoteHeaders() function.<br
/> <a
href="http://dataveld.files.wordpress.com/2015/08/pq-ch-promoteheaders.png?resize=305%2C95"><img
data-attachment-id="96" data-permalink="https://dataveld.com/pq-ch-promoteheaders/" data-orig-file="https://i2.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-promoteheaders.png?fit=305%2C95&amp;ssl=1" data-orig-size="305,95" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="PQ-CH-PromoteHeaders" data-image-description="" data-medium-file="https://i2.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-promoteheaders.png?fit=300%2C93&amp;ssl=1" data-large-file="https://i2.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-promoteheaders.png?fit=305%2C95&amp;ssl=1" class="aligncenter size-full wp-image-96" src="http://dataveld.files.wordpress.com/2015/08/pq-ch-promoteheaders.png?resize=305%2C95" alt="PQ-CH-PromoteHeaders" width="305" height="95" srcset="https://i2.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-promoteheaders.png?w=305&amp;ssl=1 305w, https://i2.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-promoteheaders.png?resize=300%2C93&amp;ssl=1 300w" sizes="(max-width: 305px) 100vw, 305px" data-recalc-dims="1" /></a></li><li>Finally, use the Table.Skip() function to remove the original headers that now appear in the first row.<br
/> <a
href="http://dataveld.files.wordpress.com/2015/08/pq-ch-skip.png?resize=302%2C75"><img
data-attachment-id="98" data-permalink="https://dataveld.com/pq-ch-skip/" data-orig-file="https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-skip.png?fit=302%2C75&amp;ssl=1" data-orig-size="302,75" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="PQ-CH-Skip" data-image-description="" data-medium-file="https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-skip.png?fit=300%2C75&amp;ssl=1" data-large-file="https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-skip.png?fit=302%2C75&amp;ssl=1" class="aligncenter size-full wp-image-98" src="http://dataveld.files.wordpress.com/2015/08/pq-ch-skip.png?resize=302%2C75" alt="PQ-CH-Skip" width="302" height="75" srcset="https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-skip.png?w=302&amp;ssl=1 302w, https://i1.wp.com/dataveld.com/wp-content/uploads/2015/08/pq-ch-skip.png?resize=300%2C75&amp;ssl=1 300w" sizes="(max-width: 302px) 100vw, 302px" data-recalc-dims="1" /></a></li></ol><p>There you have it!  Perhaps there is a better way.  <em>Hopefully</em>, there is a better way, and I am neglecting a simple function somewhere.  I would appreciate it if someone shared an improvement compared to these steps.</p><pre>let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    DemoteHeaders = Table.DemoteHeaders(Source),
    HeaderTable = DemoteHeaders,
    HeaderFirstRow = Table.FirstN(HeaderTable,1),
    HeaderTransposed = Table.Transpose(HeaderFirstRow),
    HeaderRemoveWhitespace = Table.ReplaceValue(HeaderTransposed," ","",Replacer.ReplaceText,{"Column1"}),
    HeaderTransposed2 = Table.Transpose(HeaderRemoveWhitespace),
    CombinedTables = Table.Combine({HeaderTransposed2,DemoteHeaders}),
    PromoteHeaders = Table.PromoteHeaders(CombinedTables),
    RemoveFirstRowFormerHeaders = Table.Skip(PromoteHeaders,1)
in
    RemoveFirstRowFormerHeaders</pre><p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?6bfec1&amp;6bfec1"></script><br
/> <br
/> <ins
class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-5931835938684253"
data-ad-slot="6104236328"
data-ad-format="auto"></ins><br
/><script>(adsbygoogle=window.adsbygoogle||[]).push({});</script></p><p>The post <a
rel="nofollow" href="https://dataveld.com/2015/08/08/step-by-step-using-power-query-to-replace-text-in-table-headers/">Step by Step: Using Power Query to Replace Text in Table Headers</a> appeared first on <a
rel="nofollow" href="https://dataveld.com">DataVeld</a>.</p> ]]></content:encoded> <wfw:commentRss>https://dataveld.com/2015/08/08/step-by-step-using-power-query-to-replace-text-in-table-headers/feed/</wfw:commentRss> <slash:comments>1</slash:comments> <post-id
xmlns="com-wordpress:feed-additions:1">69</post-id> </item> </channel> </rss>