<?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: Sum of a DIVIDE, then divided by DISTINCTCOUNT, then get the average across user ID column in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-of-a-DIVIDE-then-divided-by-DISTINCTCOUNT-then-get-the/m-p/3667461#M142200</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.&lt;/P&gt;
&lt;P&gt;Please check the below picture and the attached pbix file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Expected result measure: =
VAR _grossprofit =
    ADDCOLUMNS (
        SUMMARIZE ( Data, Truck[Truck ID] ),
        "@grossprofit", CALCULATE ( SUM ( Data[Gross Profit] ) ),
        "@daycount", CALCULATE ( COUNTROWS ( SUMMARIZE ( Data, 'Calendar'[Date] ) ) )
    )
VAR _dailyavg =
    ADDCOLUMNS (
        _grossprofit,
        "@dailyavg", DIVIDE ( [@grossprofit], [@daycount] ),
        "@truckcount", CALCULATE ( COUNTROWS ( SUMMARIZE ( Data, Truck[Truck ID] ) ) )
    )
VAR _result =
    AVERAGEX ( _dailyavg, DIVIDE ( [@dailyavg], [@truckcount] ) )
RETURN
    _result
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 30 Jan 2024 05:23:53 GMT</pubDate>
    <dc:creator>Jihwan_Kim</dc:creator>
    <dc:date>2024-01-30T05:23:53Z</dc:date>
    <item>
      <title>Sum of a DIVIDE, then divided by DISTINCTCOUNT, then get the average across user ID column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-of-a-DIVIDE-then-divided-by-DISTINCTCOUNT-then-get-the/m-p/3667288#M142185</link>
      <description>&lt;P&gt;Hi, I'm trying to write a complex DAX to achive a visualisation on Truck Profitability but can't seem to work it out.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;For each Truck ID, I want to get the Gross Profit per Day. Say Truck A, it will be 15/5 = 3.&lt;BR /&gt;Then, I want to sum the above up to each User ID and divide that by the distinct count of Truck ID of that user to get the Truck Profitability for each user. So for User A, it will be (3+2)/2 = 2.5&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;The DAX should also be able to show national average (i.e., average of user A &amp;amp; B) when put in a table visual.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The hard part is that not all trucks go out every day within a period (e.g., a month so 30 days) so I have to aggregate the value bottom up by considering the number of days out for each.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;User ID&lt;/TD&gt;&lt;TD&gt;Truck ID&lt;/TD&gt;&lt;TD&gt;Delivery Date&lt;/TD&gt;&lt;TD&gt;Gross Profit&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;Truck A&lt;/TD&gt;&lt;TD&gt;1/01/2024&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;Truck A&lt;/TD&gt;&lt;TD&gt;2/01/2024&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;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gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;Truck D&lt;/TD&gt;&lt;TD&gt;4/01/2024&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 30 Jan 2024 02:37:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-of-a-DIVIDE-then-divided-by-DISTINCTCOUNT-then-get-the/m-p/3667288#M142185</guid>
      <dc:creator>christinaxxx</dc:creator>
      <dc:date>2024-01-30T02:37:28Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of a DIVIDE, then divided by DISTINCTCOUNT, then get the average across user ID column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-of-a-DIVIDE-then-divided-by-DISTINCTCOUNT-then-get-the/m-p/3667461#M142200</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.&lt;/P&gt;
&lt;P&gt;Please check the below picture and the attached pbix file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Expected result measure: =
VAR _grossprofit =
    ADDCOLUMNS (
        SUMMARIZE ( Data, Truck[Truck ID] ),
        "@grossprofit", CALCULATE ( SUM ( Data[Gross Profit] ) ),
        "@daycount", CALCULATE ( COUNTROWS ( SUMMARIZE ( Data, 'Calendar'[Date] ) ) )
    )
VAR _dailyavg =
    ADDCOLUMNS (
        _grossprofit,
        "@dailyavg", DIVIDE ( [@grossprofit], [@daycount] ),
        "@truckcount", CALCULATE ( COUNTROWS ( SUMMARIZE ( Data, Truck[Truck ID] ) ) )
    )
VAR _result =
    AVERAGEX ( _dailyavg, DIVIDE ( [@dailyavg], [@truckcount] ) )
RETURN
    _result
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 05:23:53 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-of-a-DIVIDE-then-divided-by-DISTINCTCOUNT-then-get-the/m-p/3667461#M142200</guid>
      <dc:creator>Jihwan_Kim</dc:creator>
      <dc:date>2024-01-30T05:23:53Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of a DIVIDE, then divided by DISTINCTCOUNT, then get the average across user ID column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-of-a-DIVIDE-then-divided-by-DISTINCTCOUNT-then-get-the/m-p/3667464#M142201</link>
      <description>&lt;P&gt;To achieve the desired calculation of Truck Profitability for each user, you need to break down the problem into steps. You'll need to calculate the Gross Profit per Day for each truck, then sum it up for each user, and finally divide by the distinct count of Truck IDs for that user. Here's how you can do it in DAX:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Calculate Gross Profit per Day per Truck:&lt;/STRONG&gt; You need to create a measure that calculates the Gross Profit per Day for each truck. This can be done by dividing the total Gross Profit for each truck by the count of distinct delivery dates for that truck.&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Gross Profit per Day =&lt;BR /&gt;VAR TotalProfit = SUM('Table'[Gross Profit])&lt;BR /&gt;VAR DistinctDays = DISTINCTCOUNT('Table'[Delivery Date])&lt;BR /&gt;RETURN&lt;BR /&gt;DIVIDE(TotalProfit, DistinctDays, 0)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Calculate Truck Profitability for Each User:&lt;/STRONG&gt;&lt;SPAN&gt; Now, you'll sum up the Gross Profit per Day for each user and then divide it by the distinct count of Truck IDs for that user.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Truck Profitability =&lt;BR /&gt;VAR TotalProfitPerUser =&lt;BR /&gt;SUMX(&lt;BR /&gt;VALUES('Table'[User ID]),&lt;BR /&gt;[Gross Profit per Day]&lt;BR /&gt;)&lt;BR /&gt;VAR DistinctTrucksPerUser = DISTINCTCOUNT('Table'[Truck ID])&lt;BR /&gt;RETURN&lt;BR /&gt;DIVIDE(TotalProfitPerUser, DistinctTrucksPerUser, 0)&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Calculate National Average:&lt;/STRONG&gt; To calculate the national average, you can directly use the Truck Profitability measure.&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Now, you can use the Truck Profitability measure in your table visual, and it should give you the desired results. Make sure to adjust the table visuals and slicers as needed to display the data properly.&lt;/P&gt;&lt;P&gt;These measures assume that you have a table named 'Table' containing the columns User ID, Truck ID, Delivery Date, and Gross Profit. Adjust the column names accordingly if they are different in your dataset.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;P&gt;&lt;STRONG&gt;If this post&amp;nbsp;helps, then please consider&amp;nbsp;Accepting it as the solution&amp;nbsp;to help the other members find it more quickly.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;In case there is still a problem, please feel free and explain your issue in detail,&amp;nbsp;It will be my pleasure to assist you in any way I can.&lt;/STRONG&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 30 Jan 2024 05:24:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-of-a-DIVIDE-then-divided-by-DISTINCTCOUNT-then-get-the/m-p/3667464#M142201</guid>
      <dc:creator>123abc</dc:creator>
      <dc:date>2024-01-30T05:24:57Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of a DIVIDE, then divided by DISTINCTCOUNT, then get the average across user ID column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-of-a-DIVIDE-then-divided-by-DISTINCTCOUNT-then-get-the/m-p/3668899#M142267</link>
      <description>&lt;P&gt;Thank you. This worked perfectly&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 19:40:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-of-a-DIVIDE-then-divided-by-DISTINCTCOUNT-then-get-the/m-p/3668899#M142267</guid>
      <dc:creator>christinaxxx</dc:creator>
      <dc:date>2024-01-30T19:40:52Z</dc:date>
    </item>
  </channel>
</rss>

