<?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: Calculate average on the last 10 dates/records in table in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-average-on-the-last-10-dates-records-in-table/m-p/1293622#M22285</link>
    <description>That's what I was saying. I'm talking about the last 10 dates, not days. Still, if you read my comment well, you'll notice that the solution given by &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="226208" data-lia-user-login="mahoneypat" class="lia-mention lia-mention-user"&gt;mahoneypat&lt;/a&gt; is flawed. If you are taking dates that are too close to the beginning of your table, you'll end up with fewer dates(!) than 10 and you'll be thinking everything's OK.</description>
    <pubDate>Thu, 13 Aug 2020 13:32:27 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-08-13T13:32:27Z</dc:date>
    <item>
      <title>Calculate average on the last 10 dates/records in table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-average-on-the-last-10-dates-records-in-table/m-p/1290619#M22164</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Im trying to calculate average from the last 10 dates/records in my table. The table does not have consistent dates. I have created this measure but it only gives me 10 days before and up to current date and not the last 10 dates/records.&amp;nbsp; Any idea how to solve this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Measure:=CALCULATE(AVERAGE(OS[Sales]);DATESINPERIOD(OS[Date];LASTDATE(OS[Date]);-10;DAY))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Wed, 12 Aug 2020 13:46:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-average-on-the-last-10-dates-records-in-table/m-p/1290619#M22164</guid>
      <dc:creator>kjesan</dc:creator>
      <dc:date>2020-08-12T13:46:08Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate average on the last 10 dates/records in table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-average-on-the-last-10-dates-records-in-table/m-p/1290747#M22168</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="252378" data-lia-user-login="kjesan" class="lia-mention lia-mention-user"&gt;kjesan&lt;/a&gt; , try with a date calendar &lt;/P&gt;
&lt;P&gt;example&lt;/P&gt;
&lt;P&gt;Rolling 10 day = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],MAX(Sales[Sales Date]),-10,Day))&lt;/P&gt;
&lt;P&gt;Rolling 10 day = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],MAX('Date'[Date]),-10,Day))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer : &lt;BR /&gt;&lt;A href="https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions" target="_blank"&gt;https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions&lt;/A&gt; &lt;BR /&gt;&lt;A href="https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi" target="_blank"&gt;https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/" target="_blank"&gt;https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;See if my webinar on Time Intelligence can help: &lt;A href="https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-YTD-LYTD-Week-Over-Week/m-p/1051626#M184" target="_blank"&gt;https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-YTD-LYTD-Week-Over-Week/m-p/1051626#M184&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Appreciate your Kudos.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Aug 2020 14:37:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-average-on-the-last-10-dates-records-in-table/m-p/1290747#M22168</guid>
      <dc:creator>amitchandak</dc:creator>
      <dc:date>2020-08-12T14:37:05Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate average on the last 10 dates/records in table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-average-on-the-last-10-dates-records-in-table/m-p/1291260#M22194</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 your reply!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I already did all those thing you suggest, but the main problem is that the dates I have in my fact table is only workdays and sometime not all workdays in a week. So I would really need it to calculate -10 dates from my fact table and not 10 days from current date. E.g. 10 days from today will look like this: 12.08.20 - 10 days = 02.08.20 . But in my result I dont have weekends so I will only have 8 records instead of 10 in this measure.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas how to solve this?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Aug 2020 17:47:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-average-on-the-last-10-dates-records-in-table/m-p/1291260#M22194</guid>
      <dc:creator>kjesan</dc:creator>
      <dc:date>2020-08-12T17:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate average on the last 10 dates/records in table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-average-on-the-last-10-dates-records-in-table/m-p/1291590#M22223</link>
      <description>&lt;LI-CODE lang="csharp"&gt;// To do time-intel calculations
// you HAVE TO have a Dates table
// in the model. So, please
// create one according to the guidelines
// and connect to your fact table OS.
// This table should have a column that
// tells us if a day is a workday or
// a weekend day. Let's say the field
// is [Day Type] and it holds 2 values
// "Weekday" and "Weekend".
// Then your measure would be:


[Measure] =
var __totalDaysToAvgOver = 10
var __lastDate = MAX( Dates[Date] )
var __period =
    // You want to get 10 working
    // days starting from __lastDate
    // and going back.
    TOPN(__totalDaysToAvgOver,
        FILTER(
            ALL( Dates ),
            Dates[Date] &amp;lt;= __lastDate
            &amp;amp;&amp;amp;
            Dates[Day Type] = "Weekday"
        ),
        Dates[Date],
        DESC
    )
var __shouldCalc =
    COUNTROWS( __period ) = __totalDaysToAvgOver
var __result =
    if( __shouldCalc,
        AVERAGEX(
            __period,
            CALCULATE(
                0 + SUM( OS[Sales] )
            )
        )
    )
return
    __result&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 12 Aug 2020 20:28:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-average-on-the-last-10-dates-records-in-table/m-p/1291590#M22223</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-08-12T20:28:07Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate average on the last 10 dates/records in table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-average-on-the-last-10-dates-records-in-table/m-p/1291864#M22243</link>
      <description>&lt;P&gt;You can try an approach like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Last 10 Days =
VAR thisdate =
    MAX ( OS[Date] )
VAR last10days =
    TOPN ( 10, FILTER ( ALL ( OS[Date] ), OS[Date] &amp;lt;= thisdate ), OS[Date], DESC )
RETURN
    CALCULATE ( SUM ( OS[Sales] ), last10days )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this works for you, please mark it as the solution.&amp;nbsp; Kudos are appreciated too.&amp;nbsp; Please let me know if not.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Pat&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2020 01:14:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-average-on-the-last-10-dates-records-in-table/m-p/1291864#M22243</guid>
      <dc:creator>mahoneypat</dc:creator>
      <dc:date>2020-08-13T01:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate average on the last 10 dates/records in table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-average-on-the-last-10-dates-records-in-table/m-p/1293387#M22278</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="226208" data-lia-user-login="mahoneypat" class="lia-mention lia-mention-user"&gt;mahoneypat&lt;/a&gt;&amp;nbsp;it works like a charm, thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2020 11:44:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-average-on-the-last-10-dates-records-in-table/m-p/1293387#M22278</guid>
      <dc:creator>kjesan</dc:creator>
      <dc:date>2020-08-13T11:44:12Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate average on the last 10 dates/records in table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-average-on-the-last-10-dates-records-in-table/m-p/1293437#M22279</link>
      <description>&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="252378" data-lia-user-login="kjesan" class="lia-mention lia-mention-user"&gt;kjesan&lt;/a&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="226208" data-lia-user-login="mahoneypat" class="lia-mention lia-mention-user"&gt;mahoneypat&lt;/a&gt;'s solution is flawed. When you select a date that is 1st, 2nd,...,9th in your table, you will not get 10 last days but only 1, 2, 3...9 days since there's not enough days. If you then start to compare this measure among days, you'll get underestimated or exaggerated figures.</description>
      <pubDate>Thu, 13 Aug 2020 12:25:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-average-on-the-last-10-dates-records-in-table/m-p/1293437#M22279</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-08-13T12:25:11Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate average on the last 10 dates/records in table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-average-on-the-last-10-dates-records-in-table/m-p/1293442#M22280</link>
      <description>Also, what will happen if on a working day (or more such days), there are no entries in the table? You'll be skipping such a day and reaching out for many more days. Is this what you want?</description>
      <pubDate>Thu, 13 Aug 2020 12:26:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-average-on-the-last-10-dates-records-in-table/m-p/1293442#M22280</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-08-13T12:26:42Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate average on the last 10 dates/records in table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-average-on-the-last-10-dates-records-in-table/m-p/1293536#M22282</link>
      <description>&lt;P&gt;Anonymous&lt;/a&gt;&amp;nbsp;- appreciate your reply here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That is exactly what I want. I want the last 10 dates, not days. To illustrate you can see example in screenshot below where the 10 days average for 13th of august is 855,933 . You can see the values from fact table are not from consistent dates but the last 10 dates.&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;</description>
      <pubDate>Thu, 13 Aug 2020 13:04:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-average-on-the-last-10-dates-records-in-table/m-p/1293536#M22282</guid>
      <dc:creator>kjesan</dc:creator>
      <dc:date>2020-08-13T13:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate average on the last 10 dates/records in table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-average-on-the-last-10-dates-records-in-table/m-p/1293622#M22285</link>
      <description>That's what I was saying. I'm talking about the last 10 dates, not days. Still, if you read my comment well, you'll notice that the solution given by &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="226208" data-lia-user-login="mahoneypat" class="lia-mention lia-mention-user"&gt;mahoneypat&lt;/a&gt; is flawed. If you are taking dates that are too close to the beginning of your table, you'll end up with fewer dates(!) than 10 and you'll be thinking everything's OK.</description>
      <pubDate>Thu, 13 Aug 2020 13:32:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-average-on-the-last-10-dates-records-in-table/m-p/1293622#M22285</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-08-13T13:32:27Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate average on the last 10 dates/records in table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-average-on-the-last-10-dates-records-in-table/m-p/1293668#M22289</link>
      <description>&lt;P&gt;Anonymous&lt;/a&gt;&amp;nbsp;not sure if I understand exactly what you are trying to say. I have tested manually calculation to confirm that the result is correct based on what I want, and it is.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2020 13:50:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-average-on-the-last-10-dates-records-in-table/m-p/1293668#M22289</guid>
      <dc:creator>kjesan</dc:creator>
      <dc:date>2020-08-13T13:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate average on the last 10 dates/records in table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-average-on-the-last-10-dates-records-in-table/m-p/1293763#M22294</link>
      <description>&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="252378" data-lia-user-login="kjesan" class="lia-mention lia-mention-user"&gt;kjesan&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;Never mind. You'll find out what's wrong when you try to calculate 10-date average for the very first dates in your table.</description>
      <pubDate>Thu, 13 Aug 2020 14:13:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-average-on-the-last-10-dates-records-in-table/m-p/1293763#M22294</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-08-13T14:13:40Z</dc:date>
    </item>
  </channel>
</rss>

