<?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 Wrong division calculation in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Wrong-division-calculation/m-p/3149471#M112775</link>
    <description>&lt;P&gt;Hello community,&lt;/P&gt;
&lt;P&gt;It turns out that I am dividing two values, but I cannot limit the decimals on the division, then the result is not exactly correct. Any way to fix it?&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;3rd column is the substraction of 1st - 2nd. Then 5th column is the division between 3rd and 4th, which ideally would be&amp;nbsp; 60.000, but the number really is 2,50137, and it comes from (in case it helps):&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;c_YearsBetweenContractStartDateAndEndDate3 = (&lt;/SPAN&gt;&lt;SPAN&gt;DIM_Chassis&lt;/SPAN&gt;&lt;SPAN&gt;[CONTRACT_EXPIRING_DATE]&lt;/SPAN&gt;&lt;SPAN&gt; - &lt;/SPAN&gt;&lt;SPAN&gt;DIM_Chassis&lt;/SPAN&gt;&lt;SPAN&gt;[CONTRACT_START_DATE]&lt;/SPAN&gt;&lt;SPAN&gt; ) / &lt;/SPAN&gt;&lt;SPAN&gt;365. If I use YEAR() then I get 2, and I want to get decimals even if it's a year.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;Thanks in advance! &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 23 Mar 2023 10:13:49 GMT</pubDate>
    <dc:creator>Victormar</dc:creator>
    <dc:date>2023-03-23T10:13:49Z</dc:date>
    <item>
      <title>Wrong division calculation</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Wrong-division-calculation/m-p/3149471#M112775</link>
      <description>&lt;P&gt;Hello community,&lt;/P&gt;
&lt;P&gt;It turns out that I am dividing two values, but I cannot limit the decimals on the division, then the result is not exactly correct. Any way to fix it?&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;3rd column is the substraction of 1st - 2nd. Then 5th column is the division between 3rd and 4th, which ideally would be&amp;nbsp; 60.000, but the number really is 2,50137, and it comes from (in case it helps):&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;c_YearsBetweenContractStartDateAndEndDate3 = (&lt;/SPAN&gt;&lt;SPAN&gt;DIM_Chassis&lt;/SPAN&gt;&lt;SPAN&gt;[CONTRACT_EXPIRING_DATE]&lt;/SPAN&gt;&lt;SPAN&gt; - &lt;/SPAN&gt;&lt;SPAN&gt;DIM_Chassis&lt;/SPAN&gt;&lt;SPAN&gt;[CONTRACT_START_DATE]&lt;/SPAN&gt;&lt;SPAN&gt; ) / &lt;/SPAN&gt;&lt;SPAN&gt;365. If I use YEAR() then I get 2, and I want to get decimals even if it's a year.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;Thanks in advance! &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2023 10:13:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Wrong-division-calculation/m-p/3149471#M112775</guid>
      <dc:creator>Victormar</dc:creator>
      <dc:date>2023-03-23T10:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong division calculation</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Wrong-division-calculation/m-p/3153487#M113029</link>
      <description>&lt;P&gt;Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot). &lt;BR /&gt;&lt;A href="https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216" target="_blank"&gt;https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216&lt;/A&gt; &lt;BR /&gt;Please show the expected outcome based on the sample data you provided. &lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523" target="_blank"&gt;https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2023 23:36:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Wrong-division-calculation/m-p/3153487#M113029</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2023-03-24T23:36:08Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong division calculation</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Wrong-division-calculation/m-p/3155485#M113173</link>
      <description>&lt;P&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="100342" data-lia-user-login="lbendlin" class="lia-mention lia-mention-user"&gt;lbendlin&lt;/a&gt;&amp;nbsp;, sure I can post it &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;Bus&lt;/TD&gt;
&lt;TD width="25%"&gt;Contract_Start_Date&lt;/TD&gt;
&lt;TD width="25%"&gt;Contract_End_Date&lt;/TD&gt;
&lt;TD width="12.5%"&gt;Years&lt;/TD&gt;
&lt;TD width="12.5%"&gt;Years (I want)&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;1&lt;/TD&gt;
&lt;TD width="25%"&gt;2017-05-04&lt;/TD&gt;
&lt;TD width="25%"&gt;2027-05-03&lt;/TD&gt;
&lt;TD width="12.5%"&gt;10,00274&lt;/TD&gt;
&lt;TD width="12.5%"&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;2&lt;/TD&gt;
&lt;TD width="25%"&gt;2018-12-01&lt;/TD&gt;
&lt;TD width="25%"&gt;2031-11-30&lt;/TD&gt;
&lt;TD width="12.5%"&gt;13,00548&lt;/TD&gt;
&lt;TD width="12.5%"&gt;13&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;3&lt;/TD&gt;
&lt;TD width="25%"&gt;2019-03-03&lt;/TD&gt;
&lt;TD width="25%"&gt;2024-12-15&lt;/TD&gt;
&lt;TD width="12.5%"&gt;5,79178&lt;/TD&gt;
&lt;TD width="12.5%"&gt;5,79&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;4&lt;/TD&gt;
&lt;TD width="25%"&gt;2019-04-02&lt;/TD&gt;
&lt;TD width="25%"&gt;2027-04-01&lt;/TD&gt;
&lt;TD width="12.5%"&gt;8,00274&lt;/TD&gt;
&lt;TD width="12.5%"&gt;8&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;5&lt;/TD&gt;
&lt;TD width="25%"&gt;2019-08-02&lt;/TD&gt;
&lt;TD width="25%"&gt;2029-08-01&lt;/TD&gt;
&lt;TD width="12.5%"&gt;10,00548&lt;/TD&gt;
&lt;TD width="12.5%"&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;6&lt;/TD&gt;
&lt;TD width="25%"&gt;2022-06-16&lt;/TD&gt;
&lt;TD width="25%"&gt;2024-12-15&lt;/TD&gt;
&lt;TD width="12.5%"&gt;2,50137&lt;/TD&gt;
&lt;TD width="12.5%"&gt;2,50&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;My calculation for the year is: (Contract_End_Date - Contract_Start_Date) / 365&lt;/P&gt;
&lt;P&gt;The problem is I don't get exact numbers, I can get 2,50137 instead of 2,5, and I can obviously limit the display of that number to only 2 decimals and it looks good, but when calculating the total mileage per year, is looks like:&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="25%" height="57px"&gt;Bus&lt;/TD&gt;
&lt;TD width="25%" height="57px"&gt;Total_Contract_Mileage&lt;/TD&gt;
&lt;TD width="25%" height="57px"&gt;Years_of_Contract_Calculated&lt;/TD&gt;
&lt;TD width="12.5%" height="57px"&gt;Years_of_Contract (I want)&lt;/TD&gt;
&lt;TD width="6.25%" height="57px"&gt;Yearly_Mileage (Calculated)&lt;/TD&gt;
&lt;TD width="6.25%" height="57px"&gt;Yearly_Mileage (I want)&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;750000&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;10,00274&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;10&lt;/TD&gt;
&lt;TD width="6.25%" height="30px"&gt;75021&lt;/TD&gt;
&lt;TD width="6.25%" height="30px"&gt;75000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="30px"&gt;2&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;780000&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;13,00548&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;13&lt;/TD&gt;
&lt;TD width="6.25%" height="30px"&gt;60008&lt;/TD&gt;
&lt;TD width="6.25%" height="30px"&gt;60000&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;And so on...&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2023 08:28:24 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Wrong-division-calculation/m-p/3155485#M113173</guid>
      <dc:creator>Victormar</dc:creator>
      <dc:date>2023-03-27T08:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong division calculation</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Wrong-division-calculation/m-p/3159533#M113416</link>
      <description>&lt;LI-CODE lang="markup"&gt;let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Xc7RCcAwCATQXfyu4BmTprOE7r9GTQ+ENn9HnqdrCeQQN5xqXS3e4Awtw9ktn9zHEiecClfjVIMC2mzDWbARXtnAkmyMPYWeIbxgFAw1r9XB+hEFe8FZkAHfGwf/8sChGP/VDsL7AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Bus = _t, Contract_Start_Date = _t, Contract_End_Date = _t, #"Contract Mileage" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Contract_Start_Date", type date}, {"Contract_End_Date", type date}, {"Contract Mileage", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Years", each Number.Round(Number.From([Contract_End_Date]-[Contract_Start_Date])/365),Int64.Type),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Yearly Mileage", each [Contract Mileage]/[Years])
in
    #"Added Custom1"&lt;/LI-CODE&gt;
&lt;P&gt;How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2023 00:03:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Wrong-division-calculation/m-p/3159533#M113416</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2023-03-29T00:03:12Z</dc:date>
    </item>
  </channel>
</rss>

