<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Issue with Percentage Calculation in Power BI Using Databricks as Source in Get Started Discussions</title>
    <link>https://community.databricks.com/t5/get-started-discussions/issue-with-percentage-calculation-in-power-bi-using-databricks/m-p/102586#M8969</link>
    <description>&lt;P&gt;Thanks, Walter for replying, I have tried NULLIF and the nulls are being handled at Power BI. Even if I tried Coalesce the value difference is still not quiet accurate. One of metrics is Gross Profiit, my amounts are Sales - COGS and Percent is (Sales - COGS)/Sales. Because of other dimensions in my query in some rows Sales is 0 but COGS has values and but in visual it will be a different dimension and needs to match with sales and COGS accurately for mutliple customers&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Richie1602_0-1734556483920.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/13586iD70DBE6B44E72D37/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Richie1602_0-1734556483920.png" alt="Richie1602_0-1734556483920.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Dec 2024 21:19:10 GMT</pubDate>
    <dc:creator>Richie1602</dc:creator>
    <dc:date>2024-12-18T21:19:10Z</dc:date>
    <item>
      <title>Issue with Percentage Calculation in Power BI Using Databricks as Source</title>
      <link>https://community.databricks.com/t5/get-started-discussions/issue-with-percentage-calculation-in-power-bi-using-databricks/m-p/102581#M8967</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;I've created a financial summary report in Power BI, and my source is Databricks. I have created a view for each financial metric name along with the calculations. All my amount fields are accurate, but when calculating percentages, I’m getting divide-by-zero errors. I addressed this issue using Power BI, and it worked initially. but if I sort the metrics by the MetricNo column, all my custom percentages become 0, and I am unable to figure out why.&lt;/P&gt;&lt;P&gt;I have tried handling this in Databricks using null if&amp;nbsp;to ignore zeros, which gave me slightly varied percentages which is expected and I want to continue with Databricks, Is there any way I could achieve this with Databricks?&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2024 21:01:55 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/issue-with-percentage-calculation-in-power-bi-using-databricks/m-p/102581#M8967</guid>
      <dc:creator>Richie1602</dc:creator>
      <dc:date>2024-12-18T21:01:55Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Percentage Calculation in Power BI Using Databricks as Source</title>
      <link>https://community.databricks.com/t5/get-started-discussions/issue-with-percentage-calculation-in-power-bi-using-databricks/m-p/102583#M8968</link>
      <description>&lt;P&gt;Hello Richie,&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In Databricks, you can use a combination of&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;CODE&gt;NULLIF&lt;/CODE&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;and&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;CODE&gt;COALESCE&lt;/CODE&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;functions to handle divide-by-zero scenarios effectively. Here's an example of how you can modify your percentage calculation:&lt;/SPAN&gt;&lt;/P&gt;
&lt;DIV class="w-full md:max-w-[90vw]"&gt;
&lt;DIV class="codeWrapper text-textMainDark selection:!text-superDark selection:bg-superDuper/10 bg-offset dark:bg-offsetDark my-md relative flex flex-col rounded font-mono text-sm font-thin"&gt;
&lt;DIV class="top-headerHeight translate-y-xs -translate-x-xs bottom-xl mb-xl sticky flex h-0 items-start justify-end"&gt;
&lt;DIV class="flex items-center min-w-0 justify-center gap-xs"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="-mt-xl"&gt;
&lt;DIV class="pr-lg"&gt;&lt;SPAN&gt;&lt;CODE&gt;&lt;SPAN class="token token"&gt;SELECT&lt;/SPAN&gt; 
  MetricNo&lt;SPAN class="token token punctuation"&gt;,&lt;/SPAN&gt;
  MetricName&lt;SPAN class="token token punctuation"&gt;,&lt;/SPAN&gt;
  Amount&lt;SPAN class="token token punctuation"&gt;,&lt;/SPAN&gt;
  &lt;SPAN class="token token"&gt;COALESCE&lt;/SPAN&gt;&lt;SPAN class="token token punctuation"&gt;(&lt;/SPAN&gt;
    &lt;SPAN class="token token punctuation"&gt;(&lt;/SPAN&gt;Amount &lt;SPAN class="token token operator"&gt;/&lt;/SPAN&gt; &lt;SPAN class="token token"&gt;NULLIF&lt;/SPAN&gt;&lt;SPAN class="token token punctuation"&gt;(&lt;/SPAN&gt;TotalAmount&lt;SPAN class="token token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="token token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token token operator"&gt;*&lt;/SPAN&gt; &lt;SPAN class="token token"&gt;100&lt;/SPAN&gt;&lt;SPAN class="token token punctuation"&gt;,&lt;/SPAN&gt; 
    &lt;SPAN class="token token"&gt;0&lt;/SPAN&gt;
  &lt;SPAN class="token token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token token"&gt;AS&lt;/SPAN&gt; Percentage
&lt;SPAN class="token token"&gt;FROM&lt;/SPAN&gt; YourFinancialMetricsView
&lt;/CODE&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&lt;SPAN&gt;This approach works as follows:&lt;/SPAN&gt;&lt;/P&gt;
&lt;OL class="marker:text-textOff list-decimal pl-8"&gt;
&lt;LI&gt;&lt;SPAN&gt;&lt;CODE&gt;NULLIF(TotalAmount, 0)&lt;/CODE&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;returns NULL if TotalAmount is zero, avoiding the divide-by-zero error&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;If the division results in NULL (due to a zero denominator),&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;CODE&gt;COALESCE&lt;/CODE&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;will return 0 as the percentage&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Wed, 18 Dec 2024 21:05:40 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/issue-with-percentage-calculation-in-power-bi-using-databricks/m-p/102583#M8968</guid>
      <dc:creator>Walter_C</dc:creator>
      <dc:date>2024-12-18T21:05:40Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Percentage Calculation in Power BI Using Databricks as Source</title>
      <link>https://community.databricks.com/t5/get-started-discussions/issue-with-percentage-calculation-in-power-bi-using-databricks/m-p/102586#M8969</link>
      <description>&lt;P&gt;Thanks, Walter for replying, I have tried NULLIF and the nulls are being handled at Power BI. Even if I tried Coalesce the value difference is still not quiet accurate. One of metrics is Gross Profiit, my amounts are Sales - COGS and Percent is (Sales - COGS)/Sales. Because of other dimensions in my query in some rows Sales is 0 but COGS has values and but in visual it will be a different dimension and needs to match with sales and COGS accurately for mutliple customers&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Richie1602_0-1734556483920.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/13586iD70DBE6B44E72D37/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Richie1602_0-1734556483920.png" alt="Richie1602_0-1734556483920.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2024 21:19:10 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/issue-with-percentage-calculation-in-power-bi-using-databricks/m-p/102586#M8969</guid>
      <dc:creator>Richie1602</dc:creator>
      <dc:date>2024-12-18T21:19:10Z</dc:date>
    </item>
  </channel>
</rss>

