<?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: Performance Issue with AVERAGEX() in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Performance-Issue-with-AVERAGEX/m-p/2103275#M48003</link>
    <description>&lt;P&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="150936" data-lia-user-login="PaulOlding" class="lia-mention lia-mention-user"&gt;PaulOlding&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your support!&lt;/P&gt;&lt;P&gt;I've tried your formula and the performance is indeed way better.&lt;/P&gt;&lt;P&gt;Unfortunately I've made a mistake in the definition and the final value should be different.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me try to explain the expected results:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Step 1: I want to calculate column G based on E and F on the &lt;STRONG&gt;most granular level&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;Step 2: For the &lt;STRONG&gt;total&lt;/STRONG&gt;&amp;nbsp;of column G (row 5) this calculation won't be right, so I need the sum.&lt;/LI&gt;&lt;LI&gt;Step 3: I want to calculate the &lt;STRONG&gt;total&lt;/STRONG&gt; of column E, which can't be the same formula than the one on the most granular level (C divided by D) or the average (like in my original post), but I need to divide G6 by F6.&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I need two values which will be different on row level and on total level (G6 &amp;amp; E6) -&amp;nbsp;I guess, there will be might be more than one calculation needed &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you and best regards&lt;BR /&gt;Tom&lt;/P&gt;</description>
    <pubDate>Tue, 28 Sep 2021 14:32:54 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2021-09-28T14:32:54Z</dc:date>
    <item>
      <title>Performance Issue with AVERAGEX()</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Performance-Issue-with-AVERAGEX/m-p/2098473#M47875</link>
      <description>&lt;P&gt;Hi community&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a scenario where I'd like to calculate a % of reached duration.&lt;/P&gt;&lt;P&gt;Let's assume I have to Contracts A &amp;amp; B with a given contract duration ("Contract Duration").&lt;/P&gt;&lt;P&gt;The report user is now able to select a date from a slicer ("UserSelection Date").&lt;/P&gt;&lt;P&gt;Depending on this UserSelection Date I'd like to know&amp;nbsp;what percentage of the "Contract Duration" was achieved.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Product A: Because the date difference of the "Contract End" and "UserSelection Date" is only 1 day, 99.86% was achieved yet.&lt;/LI&gt;&lt;LI&gt;Product B: Because the "Contract End" is &lt;EM&gt;&lt;STRONG&gt;before&lt;/STRONG&gt; &lt;/EM&gt;"UserSelection Date", already 100% were achieved.&lt;/LI&gt;&lt;LI&gt;When there would be a product with a "Contract Start" &lt;EM&gt;&lt;STRONG&gt;after&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp;"UserSelection Date", the % of duration reached would be 0%.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;The Total of both products is nearly 100%.&lt;/P&gt;&lt;P&gt;When the user changes the "UserSelection Date" to 14.09.2022 or later, the Total is 100%:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now the calculation of the single rows is simple ("% of Duration reached Step 1"--&amp;gt; Date Diff UserSelection / Contract Duration)&lt;/P&gt;&lt;P&gt;But the calcuation of the Total differs, because you cannot take the sums of this two values.&lt;/P&gt;&lt;P&gt;That's why I'm calculating "% of Duration reached Step 2" with the AVERAGEX of the&amp;nbsp;"% of Duration reached Step 1". This will return the correct value, but is extremly slow.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have only around 2 Million rows and I'm using the import mode - but the calculation of the Step 2 takes around 1 Minute.&lt;/P&gt;&lt;P&gt;Additional information: "Product" is just one sample dimension, the formulas should work for other dimensions as well (i.e. vendor).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;UserSelection Date = MAX(Calendar[Date])

Contract Duration = 
	CALCULATE(
		SUMX(
			myTable,
			DATEDIFF ( myTable[Contract Begin], myTable[Contract End], DAY )
		)
	)

Date Diff UserSelection = 
	CALCULATE(
		SUMX(
			myTable,
			DATEDIFF ( myTable[Contract Begin], [UserSelection Date], DAY )
		)
	)

% of Duration reached Step 1 = 
	IF(
		MAX(myTable[Contract End]) &amp;lt; [UserSelection Date],
			1,
		IF(
			MAX(myTable[Contract Begin]) &amp;gt; [UserSelection Date],
				0,
				[Date Diff UserSelection] / [Contract Duration]
		)
	)

% of Duration reached Step 2 = 
	AVERAGEX(
		myTable,
		[% of Duration reached Step 1]
	)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Are there other ways to get the correct total value?&lt;/P&gt;&lt;P&gt;How can I improve the performance of this calculation?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your support!&lt;/P&gt;</description>
      <pubDate>Sun, 26 Sep 2021 13:45:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Performance-Issue-with-AVERAGEX/m-p/2098473#M47875</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-09-26T13:45:55Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue with AVERAGEX()</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Performance-Issue-with-AVERAGEX/m-p/2100447#M47927</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to recreate this with some test data that had 78k rows, so significantly less than your dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the server timings for your measures on this dataset:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I condensed it all into a single measure...&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Avg Duration = 
VAR _UserValue = MAX('User Selection'[Date])
RETURN
AVERAGEX(
	myTable,
	VAR _Num = MIN(_UserValue, myTable[Contract End]) - MIN(_UserValue, myTable[Contract Begin])
	VAR _Denom = myTable[Contract End] - myTable[Contract Begin]
	RETURN
		DIVIDE(_Num, _Denom)
)&lt;/LI-CODE&gt;&lt;P&gt;which gives these server timings.&amp;nbsp; 16 storage engine queries down to 3 and a much faster time (for my test data anyway).&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Sep 2021 13:25:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Performance-Issue-with-AVERAGEX/m-p/2100447#M47927</guid>
      <dc:creator>PaulOlding</dc:creator>
      <dc:date>2021-09-27T13:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: Performance Issue with AVERAGEX()</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Performance-Issue-with-AVERAGEX/m-p/2103275#M48003</link>
      <description>&lt;P&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="150936" data-lia-user-login="PaulOlding" class="lia-mention lia-mention-user"&gt;PaulOlding&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your support!&lt;/P&gt;&lt;P&gt;I've tried your formula and the performance is indeed way better.&lt;/P&gt;&lt;P&gt;Unfortunately I've made a mistake in the definition and the final value should be different.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me try to explain the expected results:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Step 1: I want to calculate column G based on E and F on the &lt;STRONG&gt;most granular level&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;Step 2: For the &lt;STRONG&gt;total&lt;/STRONG&gt;&amp;nbsp;of column G (row 5) this calculation won't be right, so I need the sum.&lt;/LI&gt;&lt;LI&gt;Step 3: I want to calculate the &lt;STRONG&gt;total&lt;/STRONG&gt; of column E, which can't be the same formula than the one on the most granular level (C divided by D) or the average (like in my original post), but I need to divide G6 by F6.&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I need two values which will be different on row level and on total level (G6 &amp;amp; E6) -&amp;nbsp;I guess, there will be might be more than one calculation needed &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you and best regards&lt;BR /&gt;Tom&lt;/P&gt;</description>
      <pubDate>Tue, 28 Sep 2021 14:32:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Performance-Issue-with-AVERAGEX/m-p/2103275#M48003</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-09-28T14:32:54Z</dc:date>
    </item>
  </channel>
</rss>

