<?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: Averagex not working as expected in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Averagex-not-working-as-expected/m-p/2360353#M60300</link>
    <description>&lt;P&gt;Hi&amp;nbsp; Anonymous&lt;/LI-USER&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Here are the steps you can follow：&lt;/P&gt;
&lt;P&gt;1. Create calculated table.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Date =
CALENDAR(DATE(2019,1,1),DATE(2019,12,31))&lt;/LI-CODE&gt;
&lt;P&gt;2. Create calculated column.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;left = VALUE( LEFT( RIGHT('Table'[Date Avaliavle],4),2))&lt;/LI-CODE&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;3. Create measure.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Qty_Month =
IF(
    MAX('Date'[Month])&amp;gt;=1&amp;amp;&amp;amp;MAX('Date'[Month])&amp;lt;8,CALCULATE(SUM('Table'[Qty]),FILTER(ALL('Table'),'Table'[left]=1)),CALCULATE(SUM('Table'[Qty]),FILTER(ALL('Table'),'Table'[left]=8)))&lt;/LI-CODE&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;4. Create calculated table.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Table 2 =
var _table1=SUMMARIZE('Date','Date'[Month],"if",
IF(
    'Date'[Month]&amp;gt;=1&amp;amp;&amp;amp;'Date'[Month]&amp;lt;8,CALCULATE(SUM('Table'[Qty]),FILTER(ALL('Table'),'Table'[left]=1)),CALCULATE(SUM('Table'[Qty]),FILTER(ALL('Table'),'Table'[left]=8))))
var _table2=ADDCOLUMNS(_table1,"count",COUNTX(FILTER(_table1,[if]=EARLIER([if])),[Month]))
var _table3=ADDCOLUMNS(_table2,"amount",[if]*[count])
var _table4=SUMMARIZE(_table3,[count],[amount])
return
_table4&lt;/LI-CODE&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;5. Create measure.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;average of Qty on hand =
DIVIDE( SUMX(ALL('Table 2'),[amount]),SUMX(ALL('Table 2'),[count]))&lt;/LI-CODE&gt;
&lt;P&gt;6. Result:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Liu Yang&lt;/P&gt;
&lt;P&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider &lt;EM&gt;Accept it as the solution&lt;/EM&gt; to help the other members find it more quickly&lt;/P&gt;</description>
    <pubDate>Fri, 25 Feb 2022 05:52:01 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2022-02-25T05:52:01Z</dc:date>
    <item>
      <title>Averagex not working as expected</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Averagex-not-working-as-expected/m-p/2354468#M59899</link>
      <description>&lt;P&gt;Hello ,&lt;/P&gt;&lt;P&gt;I have a fact table that contains this two value&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;SPAN&gt;i create a measure that return the Qty on hand through the year as below the result of my measure:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Now , i want to calculate the average of Qty on hand (previous result) .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I create a new measure avg , that call the previous measure like as below :&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;average of Qty on hand = averagex('Fact table',[Qty on hand])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;As below the result :&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&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;P&gt;The result that i get it isn't what i want because i get only that average (238+298)/2&amp;nbsp; (because i have only two rows on fact table)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While&amp;nbsp; i want to have an average or all the row&amp;nbsp; ((238*7)+(298*5))/12&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FYI : I want also that measure work with another context for example if i choose another dimension&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea how can i do that ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for help !!&amp;nbsp;&lt;/P&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;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 22 Feb 2022 23:56:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Averagex-not-working-as-expected/m-p/2354468#M59899</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-02-22T23:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: Averagex not working as expected</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Averagex-not-working-as-expected/m-p/2354972#M59923</link>
      <description>&lt;P&gt;Anonymous&lt;/LI-USER&gt; , Try a measure like &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;average of Qty on hand = averagex(values('Fact table'[Month Year]),[Qty on hand])&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 06:05:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Averagex-not-working-as-expected/m-p/2354972#M59923</guid>
      <dc:creator>amitchandak</dc:creator>
      <dc:date>2022-02-23T06:05:30Z</dc:date>
    </item>
    <item>
      <title>Re: Averagex not working as expected</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Averagex-not-working-as-expected/m-p/2355370#M59944</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="148838" data-lia-user-login="amitchandak" class="lia-mention lia-mention-user"&gt;amitchandak&lt;/a&gt;&amp;nbsp;thanks for the reply.&lt;/P&gt;&lt;P&gt;Well your solution doesn't work , in my fact table the granularity is date then i tried that :&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;average of Qty on hand = averagex(values('Fact table'[dateid]),[Qty on hand])&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;The result that i get is like the measure that i created before.&lt;BR /&gt;Fyi : as bellow the data that i have on my fact :&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;The measure take only those values and calculate the average&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;(238+298)/2&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;While&amp;nbsp; i want to have an average or all the row&amp;nbsp; ((238*7)+(298*5))/12&lt;/SPAN&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;P&gt;Thanks in advance for your time and help !&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 08:50:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Averagex-not-working-as-expected/m-p/2355370#M59944</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-02-23T08:50:14Z</dc:date>
    </item>
    <item>
      <title>Re: Averagex not working as expected</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Averagex-not-working-as-expected/m-p/2355446#M59953</link>
      <description>&lt;P&gt;Anonymous&lt;/a&gt; , This should happen at month year level for visual&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;average of Qty on hand = averagex(values('Fact table'[Month year]),[Qty on hand])&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;Measure 1 
average of Qty on hand day= averagex(values('Fact table'[dateid]),[Qty on hand])

Measure 2 
average of Qty on hand Month = 
averagex(values('Fact table'[Month Year]),[average of Qty on hand day])&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 09:13:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Averagex-not-working-as-expected/m-p/2355446#M59953</guid>
      <dc:creator>amitchandak</dc:creator>
      <dc:date>2022-02-23T09:13:08Z</dc:date>
    </item>
    <item>
      <title>Re: Averagex not working as expected</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Averagex-not-working-as-expected/m-p/2355522#M59959</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="148838" data-lia-user-login="amitchandak" class="lia-mention lia-mention-user"&gt;amitchandak&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But what if i want to work for all the level , i need to create all measure for different level ?&lt;/P&gt;&lt;P&gt;i will have a lot of measure ...... There are any solution to optimize that ?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;And also what if i have another dimension in my visual i think the average will only for dimension date and not another dimension&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 09:36:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Averagex-not-working-as-expected/m-p/2355522#M59959</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-02-23T09:36:38Z</dc:date>
    </item>
    <item>
      <title>Re: Averagex not working as expected</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Averagex-not-working-as-expected/m-p/2360353#M60300</link>
      <description>&lt;P&gt;Hi&amp;nbsp; Anonymous&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Here are the steps you can follow：&lt;/P&gt;
&lt;P&gt;1. Create calculated table.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Date =
CALENDAR(DATE(2019,1,1),DATE(2019,12,31))&lt;/LI-CODE&gt;
&lt;P&gt;2. Create calculated column.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;left = VALUE( LEFT( RIGHT('Table'[Date Avaliavle],4),2))&lt;/LI-CODE&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;3. Create measure.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Qty_Month =
IF(
    MAX('Date'[Month])&amp;gt;=1&amp;amp;&amp;amp;MAX('Date'[Month])&amp;lt;8,CALCULATE(SUM('Table'[Qty]),FILTER(ALL('Table'),'Table'[left]=1)),CALCULATE(SUM('Table'[Qty]),FILTER(ALL('Table'),'Table'[left]=8)))&lt;/LI-CODE&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;4. Create calculated table.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Table 2 =
var _table1=SUMMARIZE('Date','Date'[Month],"if",
IF(
    'Date'[Month]&amp;gt;=1&amp;amp;&amp;amp;'Date'[Month]&amp;lt;8,CALCULATE(SUM('Table'[Qty]),FILTER(ALL('Table'),'Table'[left]=1)),CALCULATE(SUM('Table'[Qty]),FILTER(ALL('Table'),'Table'[left]=8))))
var _table2=ADDCOLUMNS(_table1,"count",COUNTX(FILTER(_table1,[if]=EARLIER([if])),[Month]))
var _table3=ADDCOLUMNS(_table2,"amount",[if]*[count])
var _table4=SUMMARIZE(_table3,[count],[amount])
return
_table4&lt;/LI-CODE&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;5. Create measure.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;average of Qty on hand =
DIVIDE( SUMX(ALL('Table 2'),[amount]),SUMX(ALL('Table 2'),[count]))&lt;/LI-CODE&gt;
&lt;P&gt;6. Result:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Liu Yang&lt;/P&gt;
&lt;P&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider &lt;EM&gt;Accept it as the solution&lt;/EM&gt; to help the other members find it more quickly&lt;/P&gt;</description>
      <pubDate>Fri, 25 Feb 2022 05:52:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Averagex-not-working-as-expected/m-p/2360353#M60300</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-02-25T05:52:01Z</dc:date>
    </item>
  </channel>
</rss>

