{"id":71314,"date":"2017-06-09T11:19:32","date_gmt":"2017-06-09T11:19:32","guid":{"rendered":"https:\/\/www.simple-talk.com\/?p=71314"},"modified":"2021-09-07T13:41:08","modified_gmt":"2021-09-07T13:41:08","slug":"filtering-errors-in-powerbi","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/other\/filtering-errors-in-powerbi\/","title":{"rendered":"Filtering Errors in PowerBI"},"content":{"rendered":"<p>I just faced this problem when trying to analyze some information from google analytics in <strong>PowerBI<\/strong>. In my specific situation, I was trying to extract a number from some URL querystrings and filter the rows without the number. When I set the data type of the column to decimal, the rows without a number receive an expression error.\u00a0Let&#8217;s build an example filtering errors in <strong>PowerBI<\/strong>.<\/p>\n<p>The image below illustrate a small set of data in excel that will result in this problem.\u00a0The objective is to extract the numbers and exclude all the rows without numbers.\u00a0<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-71320 size-full\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2017\/06\/PBIError1.png\" alt=\"First Excel\" width=\"118\" height=\"220\" \/><\/p>\n<p>After importing the excel file in <strong>PowerBI<\/strong>, let&#8217;s extract all the content after the <em>&#8220;=&#8221;<\/em> sign using <strong>Transform<\/strong> =&gt; <strong>Extract<\/strong>=&gt; <strong>Text After Delimiter.\u00a0<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-71321 size-full\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2017\/06\/PBIError2.png\" alt=\"Extracting string\" width=\"1001\" height=\"478\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-71326 size-full\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2017\/06\/PBIError25.png\" alt=\"defining the delimiter\" width=\"878\" height=\"317\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-71331 size-full\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2017\/06\/PBIError35.png\" alt=\"middle result\" width=\"176\" height=\"240\" \/><\/p>\n<p>Now, let&#8217;s change the data type to decimal using <strong>Transform<\/strong> =&gt; <strong>Data Type<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-71322 size-full\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2017\/06\/PBIError3.png\" alt=\"changing data type\" width=\"490\" height=\"159\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>We have two errors in this resultset, as you may notice in the images below. There is no way to exclude these errors using the interface, we need to code in <strong>M<\/strong> to achieve this. There are two useful functions available to filter errors: <strong>Table.RemoveRowsWithErrors<\/strong> and <strong>Table.SelectRowsWithErrors<\/strong>, the names already explain what they do.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-71323 size-full\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2017\/06\/PBIError4.png\" alt=\"table with errors\" width=\"184\" height=\"243\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-71324 size-full\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2017\/06\/PBIError5.png\" alt=\"error message\" width=\"408\" height=\"92\" \/><\/p>\n<p>We need to open the <strong>Advanced Editor<\/strong>, inside <strong>View<\/strong>, to edit the <strong>M<\/strong> code.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-71325 size-full\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2017\/06\/PBIError6.png\" alt=\"Editing M\" width=\"293\" height=\"175\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-71327 size-full\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2017\/06\/PBIError65.png\" alt=\"Initial Code\" width=\"1245\" height=\"362\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>We will add a new line before the <em>&#8220;In&#8221;<\/em> statement. In this line, we will create a new name for our result, like this:<\/p>\n<pre class=\"lang:vbnet decode:true\">#\"Result without errors\" =<\/pre>\n<p>After the <em>&#8220;=&#8221;<\/em> sign we can use the function, it has two parameters: The name of the result of the previous line and the column we want to check for errors.<\/p>\n<pre class=\"lang:vbnet decode:true\">#\"Result without errors\" =Table.RemoveRowsWithErrors(#\"Changed Type1\", {\"Column1\"})<\/pre>\n<p>Two more details to go:<\/p>\n<ul>\n<li>The previous line need an extra comma at the end<\/li>\n<li>After the &#8220;in&#8221; statement, we need to change the name of the final result set to our new name<\/li>\n<\/ul>\n<pre class=\"lang:vbnet decode:true\">in\r\n   #\"Result without errors\"<\/pre>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-71330 size-full\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2017\/06\/PBIError7.png\" alt=\"final code\" width=\"1226\" height=\"321\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>The final result, without the errors:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-71329 size-full\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2017\/06\/PBIError8.png\" alt=\"Final Result filtering errors in powerbi\" width=\"174\" height=\"186\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I just faced this problem when trying to analyze some information from google analytics in PowerBI. In my specific situation, I was trying to extract a number from some URL querystrings and filter the rows without the number. When I set the data type of the column to decimal, the rows without a number receive&#8230;&hellip;<\/p>\n","protected":false},"author":50808,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[],"coauthors":[6810],"class_list":["post-71314","post","type-post","status-publish","format-standard","hentry","category-other"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/71314","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/50808"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=71314"}],"version-history":[{"count":2,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/71314\/revisions"}],"predecessor-version":[{"id":92372,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/71314\/revisions\/92372"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=71314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=71314"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=71314"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=71314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}