<?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: DAX formula to calculate rolling X average based on parameter &amp;amp; values from other columns in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-formula-to-calculate-rolling-X-average-based-on-parameter/m-p/2073185#M46935</link>
    <description>&lt;P&gt;Hi amitchandak,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the response. I already have the week numbers so no need to create a weekrank function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to adapt your code, and I think we're getting somewhere.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Forecast DAX = CALCULATE(AVERAGE('Sample'[Actual]),FILTER(ALL('Sample'),'Sample'[Week #]&amp;gt;=[Current Week]-8 &amp;amp;&amp;amp; 'Sample'[Week #]&amp;lt;[Current Week]))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It still lacks the additional conditions that I mentioned earlier. I'm trying to do something like this, but I'm not finding the right syntax:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Forecast DAX = CALCULATE(AVERAGE('Sample'[Actual]),FILTER(ALL('Sample'),'Sample'[Week #]&amp;gt;=[Current Week]-8 &amp;amp;&amp;amp; 'Sample'[Week #]&amp;lt;[Current Week]) &amp;amp;&amp;amp; 'Sample'[FY]=rowvalue(FY) &amp;amp;&amp;amp; 'Sample'[KPI]=rowvalue(KPI) &amp;amp;&amp;amp; 'Sample'[Owner]=rowvalue(Owner))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know that rowvalue is not a real function, but it demonstrates what I'm trying to do. There are 3 additional filters for me to use so that the AVERAGE function only calculates if the FY, KPI, and Owner columns match the current row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also tried this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Forecast DAX = CALCULATE(AVERAGE('Sample'[Actual]),FILTER(ALL('Sample'),'Sample'[Week #]&amp;gt;=[Current Week]-8 &amp;amp;&amp;amp; 'Sample'[Week #]&amp;lt;[Current Week]) &amp;amp;&amp;amp; 'Sample'[FY]=earlier('Sample'[FY]) &amp;amp;&amp;amp; 'Sample'[KPI]=earlier('Sample'[KPI]) &amp;amp;&amp;amp; 'Sample'[Owner]=earlier('Sample'[Owner]))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I am getting this error:&lt;/P&gt;&lt;P&gt;A function 'FILTER' has been used in a True/False expression that is used as a table filter expression. This is not allowed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's not very helpful. I just added conditions via &amp;amp;&amp;amp; and didn't add any FILTER functions, so I don't know what's wrong.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would you be able to help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Andrew&lt;/P&gt;</description>
    <pubDate>Mon, 13 Sep 2021 15:12:43 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2021-09-13T15:12:43Z</dc:date>
    <item>
      <title>DAX formula to calculate rolling X average based on parameter &amp; values from other columns</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-formula-to-calculate-rolling-X-average-based-on-parameter/m-p/2072951#M46917</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a Column using DAX that calculates a rolling 8-week average based on a parameter/measure with multiple filters depending on the values of other columns.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data Structure:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is also a parameter for the current week number in cell K2:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The column &lt;U&gt;Forecast&lt;/U&gt; is what I am trying to create using DAX.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What it does is:&lt;/P&gt;&lt;P&gt;- If the week number is less than or equal to the Current Week, just copy the value under "Actual" (Column E)&lt;/P&gt;&lt;P&gt;- Else, get the average of "Actual" (Column E) of the 8 weeks prior to the current week (if Current Week = 38, get average of weeks 30-37), subject to having the same FY, same KPI, and same Owner with the current row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In Excel, the correct formula for Row #2 would be:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;=IF(
    B2&amp;lt;=$K$2,
    E2,
    AVERAGEIFS(
        E:E,
        B:B,"&amp;lt;"&amp;amp;$K$2,
        B:B,"&amp;gt;="&amp;amp;$K$2-8,
        D:D,D2,
        C:C,C2,
        A:A,A2
    )
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am really struggling to find the right DAX syntax because I can't seem to figure out how to pass one of the values of the current row into the DAX filters. I tried doing something like this (without the IF statement) but obviously it's not working:&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;I have uploaded the sample Excel and PBIX files for easier reference. You can see how the correct calculation is done in Excel.&lt;/P&gt;&lt;P&gt;- XLSX: &lt;A href="https://docs.google.com/spreadsheets/d/1fYG1dRtkthvLhxMTDXxbx1x_VmoVxf0Y/edit?usp=sharing&amp;amp;ouid=111734964497020988818&amp;amp;rtpof=true&amp;amp;sd=true" target="_blank"&gt;https://docs.google.com/spreadsheets/d/1fYG1dRtkthvLhxMTDXxbx1x_VmoVxf0Y/edit?usp=sharing&amp;amp;ouid=111734964497020988818&amp;amp;rtpof=true&amp;amp;sd=true&lt;/A&gt;&lt;/P&gt;&lt;P&gt;- PBIX: &lt;A href="https://drive.google.com/file/d/1TqT_xKZg3s7sSyZJr4yrQPtt-iW4mU8I/view?usp=sharing" target="_blank"&gt;https://drive.google.com/file/d/1TqT_xKZg3s7sSyZJr4yrQPtt-iW4mU8I/view?usp=sharing&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help will be greatly appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Andrew&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 13:33:39 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-formula-to-calculate-rolling-X-average-based-on-parameter/m-p/2072951#M46917</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-09-13T13:33:39Z</dc:date>
    </item>
    <item>
      <title>Re: DAX formula to calculate rolling X average based on parameter &amp; values from other columns</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-formula-to-calculate-rolling-X-average-based-on-parameter/m-p/2073073#M46927</link>
      <description>&lt;P&gt;Anonymous&lt;/LI-USER&gt; , For week , I usually create a week rank in date table and use that&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;New column&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Week Rank = RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;measures &lt;BR /&gt;Last 8 weeks = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]&amp;gt;=max('Date'[Week Rank])-8 &amp;amp;&amp;amp; 'Date'[Week Rank]&amp;lt;=max('Date'[Week Rank])))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Power BI — Week on Week and WTD &lt;BR /&gt;&lt;A href="https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3" target="_blank" rel="noopener"&gt;https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-Last-Week/ba-p/1051123" target="_blank" rel="noopener"&gt;https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-Last-Week/ba-p/1051123&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://www.youtube.com/watch?v=pnAesWxYgJ8" target="_blank" rel="noopener"&gt;https://www.youtube.com/watch?v=pnAesWxYgJ8&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 14:24:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-formula-to-calculate-rolling-X-average-based-on-parameter/m-p/2073073#M46927</guid>
      <dc:creator>amitchandak</dc:creator>
      <dc:date>2021-09-13T14:24:56Z</dc:date>
    </item>
    <item>
      <title>Re: DAX formula to calculate rolling X average based on parameter &amp; values from other columns</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-formula-to-calculate-rolling-X-average-based-on-parameter/m-p/2073185#M46935</link>
      <description>&lt;P&gt;Hi amitchandak,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the response. I already have the week numbers so no need to create a weekrank function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to adapt your code, and I think we're getting somewhere.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Forecast DAX = CALCULATE(AVERAGE('Sample'[Actual]),FILTER(ALL('Sample'),'Sample'[Week #]&amp;gt;=[Current Week]-8 &amp;amp;&amp;amp; 'Sample'[Week #]&amp;lt;[Current Week]))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It still lacks the additional conditions that I mentioned earlier. I'm trying to do something like this, but I'm not finding the right syntax:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Forecast DAX = CALCULATE(AVERAGE('Sample'[Actual]),FILTER(ALL('Sample'),'Sample'[Week #]&amp;gt;=[Current Week]-8 &amp;amp;&amp;amp; 'Sample'[Week #]&amp;lt;[Current Week]) &amp;amp;&amp;amp; 'Sample'[FY]=rowvalue(FY) &amp;amp;&amp;amp; 'Sample'[KPI]=rowvalue(KPI) &amp;amp;&amp;amp; 'Sample'[Owner]=rowvalue(Owner))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know that rowvalue is not a real function, but it demonstrates what I'm trying to do. There are 3 additional filters for me to use so that the AVERAGE function only calculates if the FY, KPI, and Owner columns match the current row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also tried this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Forecast DAX = CALCULATE(AVERAGE('Sample'[Actual]),FILTER(ALL('Sample'),'Sample'[Week #]&amp;gt;=[Current Week]-8 &amp;amp;&amp;amp; 'Sample'[Week #]&amp;lt;[Current Week]) &amp;amp;&amp;amp; 'Sample'[FY]=earlier('Sample'[FY]) &amp;amp;&amp;amp; 'Sample'[KPI]=earlier('Sample'[KPI]) &amp;amp;&amp;amp; 'Sample'[Owner]=earlier('Sample'[Owner]))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I am getting this error:&lt;/P&gt;&lt;P&gt;A function 'FILTER' has been used in a True/False expression that is used as a table filter expression. This is not allowed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's not very helpful. I just added conditions via &amp;amp;&amp;amp; and didn't add any FILTER functions, so I don't know what's wrong.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would you be able to help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Andrew&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 15:12:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-formula-to-calculate-rolling-X-average-based-on-parameter/m-p/2073185#M46935</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-09-13T15:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: DAX formula to calculate rolling X average based on parameter &amp; values from other columns</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-formula-to-calculate-rolling-X-average-based-on-parameter/m-p/2073230#M46939</link>
      <description>&lt;P&gt;I found the solution!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Forecast DAX = IF('Sample'[Week #]&amp;lt;=[Current Week],'Sample'[Actual],CALCULATE(AVERAGE('Sample'[Actual]),FILTER(ALL('Sample'),'Sample'[Week #]&amp;gt;=[Current Week]-8 &amp;amp;&amp;amp; 'Sample'[Week #]&amp;lt;[Current Week]),FILTER(all('Sample'),'Sample'[FY]=earlier('Sample'[FY])),FILTER(ALL('Sample'),'Sample'[KPI]=EARLIER('Sample'[KPI])),FILTER(ALL('Sample'),'Sample'[Owner]=earlier('Sample'[Owner]))))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I learned the following:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;You can't just keep adding &amp;amp;&amp;amp;s as additional conditions. You have to create separate FILTER arguments for each. Not very intuitive, but good to know.&lt;/LI&gt;&lt;LI&gt;EARLIER actually is the function to reference the &lt;STRONG&gt;current&lt;/STRONG&gt; row's value, not the previous one. Again, not very intuitive, but now I know better.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you amitchandak, your reply might not have been the solution, but it was helpful for me to think this through!&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 15:25:58 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-formula-to-calculate-rolling-X-average-based-on-parameter/m-p/2073230#M46939</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-09-13T15:25:58Z</dc:date>
    </item>
  </channel>
</rss>

