<?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: Weighted Time Average from table of times. in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Weighted-Time-Average-from-table-of-times/m-p/3672600#M142479</link>
    <description>&lt;P&gt;Hi Anonymous&lt;/LI-USER&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope everything is going well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Based on your description I would create an intermediate table and then create measures to calculate the weighted average.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Based on the fields you provide, select New Table in the Model view.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The DAX syntax is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Intermediate Table =
ADDCOLUMNS(
SUMMARIZECOLUMNS(
'Table'[Event Time],
'Table'[Active Quantity],
"End Time",
CALCULATE(
MIN('Table'[Event Time]),
FILTER(
ALL('Table'),
'Table'[Event Time] &amp;gt; MAX('Table'[Event Time])
)
)
),
"Hours Difference",
DATEDIFF(
'Table'[Event Time],
[End Time],
HOUR
)
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After successful creation, the data is displayed as follows:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next, create a measure to calculate the weighted average. The DAX syntax is as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Weighted Average Active Quantity =
SUMX(
'Intermediate Table',
[Active Quantity] * [Hours Difference]
)
/ SUM('Intermediate Table'[Hours Difference])&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After creation, the data can be displayed in the "Report" view. The "Table" visual object is used to display the intermediate table, and the "Card" visual object is used to display the weighted average. The effect is as follows:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Power BI Desktop add-on attached.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have any further questions please feel free to contact me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Yang&lt;BR /&gt;Community Support Team&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there is any post&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;helps&lt;/EM&gt;&lt;/STRONG&gt;, then please consider&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Accept it as the solution&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;to help the other members find it more quickly.&lt;BR /&gt;If I misunderstand your needs or you still have problems on it, please feel free to let us know.&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Thanks a lot!&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 01 Feb 2024 09:44:41 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2024-02-01T09:44:41Z</dc:date>
    <item>
      <title>Weighted Time Average from table of times.</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Weighted-Time-Average-from-table-of-times/m-p/3670004#M142330</link>
      <description>&lt;P&gt;I've got a calendar table of dates, and have created a&amp;nbsp;&lt;SPAN&gt;SUMMARIZECOLUMNS&amp;nbsp;&lt;/SPAN&gt;measure that tabulates every 'event time' within that day, and the active quantity at that time. For example, for the 29th of January this table is generated:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Event Time&lt;/TD&gt;&lt;TD&gt;Active Quantity&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;29/01/2024 08:00&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;29/01/2024 09:00&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;125&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;29/01/2024 12:00&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;300&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;29/01/2024 15:00&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;300&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;29/01/2024 17:00&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;29/01/2024 22:00&lt;/TD&gt;&lt;TD&gt;25&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;BR /&gt;I'm trying to calculate the Average Active Quantity, weighted by the amount of time between Events. To calculate this I need to generate an intermediate table, with each time period:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Start Time&lt;/TD&gt;&lt;TD&gt;End Time&lt;/TD&gt;&lt;TD&gt;Hours Difference&lt;/TD&gt;&lt;TD&gt;Active Quantity&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;29/01/2024 08:00&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;29/01/2024 09:00&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;1&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;29/01/2024 09:00&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;29/01/2024 12:00&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;3&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;125&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;29/01/2024 12:00&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;29/01/2024 15:00&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;3&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;300&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;29/01/2024 15:00&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;29/01/2024 17:00&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;2&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;300&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;29/01/2024 17:00&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;29/01/2024 22:00&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;5&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How would I generate this table, and finally calculate the Average of 'Active Quantity' weighted by 'Hours Difference' in one measure?&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2024 10:37:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Weighted-Time-Average-from-table-of-times/m-p/3670004#M142330</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-01-31T10:37:35Z</dc:date>
    </item>
    <item>
      <title>Re: Weighted Time Average from table of times.</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Weighted-Time-Average-from-table-of-times/m-p/3670098#M142337</link>
      <description>&lt;P&gt;To achieve this in Power BI, you can follow these steps:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;STRONG&gt;Generate the intermediate table&lt;/STRONG&gt; with start time, end time, hours difference, and active quantity.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Calculate the weighted average&lt;/STRONG&gt; using DAX measures.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Here's how you can generate the intermediate table in Power BI:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IntermediateTable =&lt;BR /&gt;VAR MaxIndex = COUNTROWS('YourTable') - 1&lt;BR /&gt;RETURN&lt;BR /&gt;ADDCOLUMNS (&lt;BR /&gt;GENERATESERIES(0, MaxIndex - 1, 1),&lt;BR /&gt;"Start Time", 'YourTable'[Event Time],&lt;BR /&gt;"End Time", 'YourTable'[Event Time] + TIME(1, 0, 0),&lt;BR /&gt;"Hours Difference",&lt;BR /&gt;IF(&lt;BR /&gt;[Index] = 0,&lt;BR /&gt;HOUR('YourTable'[Event Time] + TIME(1, 0, 0) - 'YourTable'[Event Time]),&lt;BR /&gt;HOUR('YourTable'[Event Time] + TIME(1, 0, 0) - 'YourTable'[Event Time + [Index]])&lt;BR /&gt;),&lt;BR /&gt;"Active Quantity", 'YourTable'[Active Quantity]&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Explanation:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;MaxIndex finds the maximum index of the table.&lt;/LI&gt;&lt;LI&gt;GENERATESERIES generates a series from 0 to MaxIndex - 1.&lt;/LI&gt;&lt;LI&gt;ADDCOLUMNS creates new columns for the intermediate table.&lt;/LI&gt;&lt;LI&gt;"Start Time" and "End Time" are the same as the original time but with an added hour.&lt;/LI&gt;&lt;LI&gt;"Hours Difference" calculates the difference in hours between consecutive event times.&lt;/LI&gt;&lt;LI&gt;"Active Quantity" brings the active quantity from your original table.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Now, to calculate the weighted average of 'Active Quantity' by 'Hours Difference', you can use the following measure:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;WeightedAverage =&lt;BR /&gt;DIVIDE(&lt;BR /&gt;SUMX('IntermediateTable', 'IntermediateTable'[Active Quantity] * 'IntermediateTable'[Hours Difference]),&lt;BR /&gt;SUM('IntermediateTable'[Hours Difference])&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This measure iterates over the rows of the intermediate table, multiplies the 'Active Quantity' by 'Hours Difference', sums up the results, and then divides it by the sum of 'Hours Difference'.&lt;/P&gt;&lt;P&gt;You can now use the WeightedAverage measure in your reports to get the desired result. Make sure to adjust column and table names according to your actual data model in Power BI.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&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;</description>
      <pubDate>Wed, 31 Jan 2024 11:13:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Weighted-Time-Average-from-table-of-times/m-p/3670098#M142337</guid>
      <dc:creator>123abc</dc:creator>
      <dc:date>2024-01-31T11:13:41Z</dc:date>
    </item>
    <item>
      <title>Re: Weighted Time Average from table of times.</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Weighted-Time-Average-from-table-of-times/m-p/3672600#M142479</link>
      <description>&lt;P&gt;Hi Anonymous&lt;/LI-USER&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope everything is going well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Based on your description I would create an intermediate table and then create measures to calculate the weighted average.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Based on the fields you provide, select New Table in the Model view.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The DAX syntax is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Intermediate Table =
ADDCOLUMNS(
SUMMARIZECOLUMNS(
'Table'[Event Time],
'Table'[Active Quantity],
"End Time",
CALCULATE(
MIN('Table'[Event Time]),
FILTER(
ALL('Table'),
'Table'[Event Time] &amp;gt; MAX('Table'[Event Time])
)
)
),
"Hours Difference",
DATEDIFF(
'Table'[Event Time],
[End Time],
HOUR
)
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After successful creation, the data is displayed as follows:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next, create a measure to calculate the weighted average. The DAX syntax is as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Weighted Average Active Quantity =
SUMX(
'Intermediate Table',
[Active Quantity] * [Hours Difference]
)
/ SUM('Intermediate Table'[Hours Difference])&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After creation, the data can be displayed in the "Report" view. The "Table" visual object is used to display the intermediate table, and the "Card" visual object is used to display the weighted average. The effect is as follows:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Power BI Desktop add-on attached.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have any further questions please feel free to contact me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Yang&lt;BR /&gt;Community Support Team&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there is any post&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;helps&lt;/EM&gt;&lt;/STRONG&gt;, then please consider&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Accept it as the solution&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;to help the other members find it more quickly.&lt;BR /&gt;If I misunderstand your needs or you still have problems on it, please feel free to let us know.&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Thanks a lot!&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2024 09:44:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Weighted-Time-Average-from-table-of-times/m-p/3672600#M142479</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-02-01T09:44:41Z</dc:date>
    </item>
  </channel>
</rss>

