<?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: Having problems with previous weeks data in Desktop</title>
    <link>https://community.fabric.microsoft.com/t5/Desktop/Having-problems-with-previous-weeks-data/m-p/4268111#M1340887</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="419403" data-lia-user-login="vsmn" class="lia-mention lia-mention-user"&gt;vsmn&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;here's a simple version:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;previousWeekTotal = 
var currentWeek = SELECTEDVALUE('Table'[week])
var previousWeek = MAXX(FILTER(ALL('Table'[week]), 'Table'[week] &amp;lt; currentWeek), 'Table'[week])
var result =  
CALCULATE(
    [total],
    'Table'[week] = previousWeek
)

return result&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I would scratch the "-1" check and just get any first value that is lower than current value (week).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Alternative and that'S what you want, you can show blank if it's not the right week like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;previousWeekTotal = 
var currentWeek = SELECTEDVALUE('Table'[week])
var previousWeek = MAXX(FILTER(ALL('Table'[week]), 'Table'[week] &amp;lt; currentWeek), 'Table'[week])
var result =  
CALCULATE(
    [total],
    'Table'[week] = previousWeek
)
var isFollowing = IF(previousWeek = (currentWeek-1), result, BLANK())

return isFollowing&lt;/LI-CODE&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>Sun, 03 Nov 2024 16:34:31 GMT</pubDate>
    <dc:creator>vojtechsima</dc:creator>
    <dc:date>2024-11-03T16:34:31Z</dc:date>
    <item>
      <title>Having problems with previous weeks data</title>
      <link>https://community.fabric.microsoft.com/t5/Desktop/Having-problems-with-previous-weeks-data/m-p/4268087#M1340873</link>
      <description>&lt;P&gt;I can't seem to get this working, has the result is somewhat incorrect.&lt;/P&gt;&lt;P&gt;I would like to display the previous week SUM or AVERAGE. There can be cases of non existent data in the previous week, for example:&lt;/P&gt;&lt;P&gt;Week 40 = 100&lt;/P&gt;&lt;P&gt;Week 39 = 101&lt;/P&gt;&lt;P&gt;Week 37 = 90&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my table I have a column for the week number, and this is the measure I have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Average Previous Week = 
VAR CurrentWeek = MAX(Carregar[Week of Year])
VAR CurrentTotal = AVERAGE(Carregar[Price])
VAR previous_price = 
    CALCULATE(
        AVERAGE(Carregar[Price]),
        FILTER(
            ALL(Carregar[Week of Year]),
            Carregar[Week of Year] = CurrentWeek - 1
    )
    )
RETURN
IF(
    ISBLANK(previous_price),
    CurrentTotal,previous_price
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;Somehow the result is innacurate:&lt;BR /&gt;&lt;img /&gt;&lt;P&gt;What am I doing wrong?&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Sun, 03 Nov 2024 15:40:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Desktop/Having-problems-with-previous-weeks-data/m-p/4268087#M1340873</guid>
      <dc:creator>vsmn</dc:creator>
      <dc:date>2024-11-03T15:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: Having problems with previous weeks data</title>
      <link>https://community.fabric.microsoft.com/t5/Desktop/Having-problems-with-previous-weeks-data/m-p/4268096#M1340878</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="419403" data-lia-user-login="vsmn" class="lia-mention lia-mention-user"&gt;vsmn&lt;/a&gt;&amp;nbsp;-&amp;nbsp;I see the problem with your measure. The issue is likely occurring because ALL(Carregar[Week of Year]) removes all filters on the week context, causing unexpected results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;updated measure: can you please check with below&lt;/P&gt;
&lt;P&gt;Average Previous Week = &lt;BR /&gt;VAR CurrentWeek = MAX(Carregar[Week of Year])&lt;BR /&gt;VAR PreviousWeek =&lt;BR /&gt;MAXX(&lt;BR /&gt;FILTER(&lt;BR /&gt;ALL(Carregar),&lt;BR /&gt;Carregar[Week of Year] &amp;lt; CurrentWeek &amp;amp;&amp;amp; NOT(ISBLANK(Carregar[Price]))&lt;BR /&gt;),&lt;BR /&gt;Carregar[Week of Year]&lt;BR /&gt;)&lt;BR /&gt;VAR PreviousWeekPrice = &lt;BR /&gt;CALCULATE(&lt;BR /&gt;AVERAGE(Carregar[Price]),&lt;BR /&gt;Carregar[Week of Year] = PreviousWeek&lt;BR /&gt;)&lt;BR /&gt;RETURN&lt;BR /&gt;IF(&lt;BR /&gt;ISBLANK(PreviousWeekPrice),&lt;BR /&gt;BLANK(), // or use CurrentTotal if you want to default to current average&lt;BR /&gt;PreviousWeekPrice&lt;BR /&gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,try applying this measure, and let me know if it resolves the issue in your table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Nov 2024 16:11:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Desktop/Having-problems-with-previous-weeks-data/m-p/4268096#M1340878</guid>
      <dc:creator>rajendraongole1</dc:creator>
      <dc:date>2024-11-03T16:11:12Z</dc:date>
    </item>
    <item>
      <title>Re: Having problems with previous weeks data</title>
      <link>https://community.fabric.microsoft.com/t5/Desktop/Having-problems-with-previous-weeks-data/m-p/4268111#M1340887</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="419403" data-lia-user-login="vsmn" class="lia-mention lia-mention-user"&gt;vsmn&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;here's a simple version:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;previousWeekTotal = 
var currentWeek = SELECTEDVALUE('Table'[week])
var previousWeek = MAXX(FILTER(ALL('Table'[week]), 'Table'[week] &amp;lt; currentWeek), 'Table'[week])
var result =  
CALCULATE(
    [total],
    'Table'[week] = previousWeek
)

return result&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I would scratch the "-1" check and just get any first value that is lower than current value (week).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Alternative and that'S what you want, you can show blank if it's not the right week like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;previousWeekTotal = 
var currentWeek = SELECTEDVALUE('Table'[week])
var previousWeek = MAXX(FILTER(ALL('Table'[week]), 'Table'[week] &amp;lt; currentWeek), 'Table'[week])
var result =  
CALCULATE(
    [total],
    'Table'[week] = previousWeek
)
var isFollowing = IF(previousWeek = (currentWeek-1), result, BLANK())

return isFollowing&lt;/LI-CODE&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>Sun, 03 Nov 2024 16:34:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Desktop/Having-problems-with-previous-weeks-data/m-p/4268111#M1340887</guid>
      <dc:creator>vojtechsima</dc:creator>
      <dc:date>2024-11-03T16:34:31Z</dc:date>
    </item>
  </channel>
</rss>

