<?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: Calculating a week before value in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-a-week-before-value/m-p/1813487#M38337</link>
    <description>&lt;P&gt;HI&amp;nbsp;Anonymous&lt;/LI-USER&gt;.&amp;nbsp;Thanks. Yes, I created a date table, you can see my file above. I'm just stuck on the -7 days part.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically I need the number 7 days before the measure below. I'm unsure how to do that.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;CALCULATE (
    SUM( covidpercounty[ConfirmedCovidCases] ),
    FILTER ( 'Date', WEEKDAY ('Date'[Date] ) = 1 )
)&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 29 Apr 2021 08:43:59 GMT</pubDate>
    <dc:creator>MargaretJames</dc:creator>
    <dc:date>2021-04-29T08:43:59Z</dc:date>
    <item>
      <title>Calculating a week before value</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-a-week-before-value/m-p/1811341#M38256</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to calculate the total week value in a table. I would like to subtract the week before value from the current week. I'm having an issue with my week before value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I created a measure like this:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Amount-Week before = 
CALCULATE (
    SUM( covidpercounty[ConfirmedCovidCases] ),
    FILTER ( 'Date', WEEKDAY ('Date'[Date] ) = 1 &amp;amp;&amp;amp; WEEKNUM(TODAY(),1)-1)
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But this is giving me the current week value. It should give me the previous week value. So for week 11, the week before value should be 0 and week 12, it should be 3.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;I would then like to just subtract previous week from current week to calculate the total.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Total per week = 
Var WeekBefore = 
CALCULATE (
    SUM( covidpercounty[ConfirmedCovidCases] ),
    FILTER ( 'Date', WEEKDAY ('Date'[Date] ) = 1 &amp;amp;&amp;amp; WEEKNUM(TODAY(),1)-1)
)

Var ThisWeek =  
CALCULATE (
    SUM( covidpercounty[ConfirmedCovidCases] ),
    FILTER ( 'Date', WEEKDAY ('Date'[Date] ) = 1 )
)

Var Total = ThisWeek - WeekBefore

return

Var Total&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;I've incuded the file &lt;A href="https://www.dropbox.com/s/mnqri2ys9eqxrre/CovidTest.pbix?dl=0" target="_self"&gt;here&lt;/A&gt;. Thanks for any help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Apr 2021 11:32:53 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-a-week-before-value/m-p/1811341#M38256</guid>
      <dc:creator>MargaretJames</dc:creator>
      <dc:date>2021-04-28T11:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating a week before value</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-a-week-before-value/m-p/1811344#M38257</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="297591" data-lia-user-login="MargaretJames" class="lia-mention lia-mention-user"&gt;MargaretJames&lt;/a&gt; . please refer to my blog or video for WOW &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3" target="_blank"&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"&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"&gt;https://www.youtube.com/watch?v=pnAesWxYgJ8&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Apr 2021 11:35:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-a-week-before-value/m-p/1811344#M38257</guid>
      <dc:creator>amitchandak</dc:creator>
      <dc:date>2021-04-28T11:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating a week before value</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-a-week-before-value/m-p/1811577#M38272</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 but I'm just taking the value of one day per week. This works fine.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Amount-Week before = 
CALCULATE (
    SUM( covidpercounty[ConfirmedCovidCases] ),
    FILTER ( 'Date', WEEKDAY ('Date'[Date] ) = 1 &amp;amp;&amp;amp; WEEKNUM(TODAY(),1)-1)
)&lt;/LI-CODE&gt;&lt;P&gt;But I need to get the value for the previous week where Weekday is 1. Could you have a look at my file above please?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Apr 2021 13:13:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-a-week-before-value/m-p/1811577#M38272</guid>
      <dc:creator>MargaretJames</dc:creator>
      <dc:date>2021-04-28T13:13:33Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating a week before value</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-a-week-before-value/m-p/1812456#M38309</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="297591" data-lia-user-login="MargaretJames" class="lia-mention lia-mention-user"&gt;MargaretJames&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To have correct DAX formulas that work in all circumstances you have to follow certain rules. Deviate from them and you'll be in for a surprise. So, first off, to create correct time calculations you have to have a proper date table in the model with all time pieces that you'll need. Also, forget about WEEKNUM. This function &lt;STRONG&gt;does not&lt;/STRONG&gt; work the way most people would expect it to (&lt;A href="https://dax.guide/weeknum" target="_blank"&gt;https://dax.guide/weeknum&lt;/A&gt;).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To correctly do what you want you have to create a proper date table where each day will be assigned to a unique week and each week will be 7 days long as it should. &lt;EM&gt;WEEKNUM does not guarantee this&lt;/EM&gt;. Once you have a date table (call it Dates) with a column with unique week identifiers (call it Year-Week and give it the format YYYY-WKXX, where XX goes from 01 through to 53), you can now create the correct calculations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To see how such a setup should work (or a setup with some ISO Week calendars), please consult the articles at &lt;A href="http://www.sqlbi.com" target="_blank"&gt;www.sqlbi.com&lt;/A&gt;. They have plenty of articles on how to correctly do week-based calculations. Please do not try to re-invent the wheel. It's tricky in DAX, to say the least, if you're not good at it. Saying from experience.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Apr 2021 21:43:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-a-week-before-value/m-p/1812456#M38309</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-04-28T21:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating a week before value</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-a-week-before-value/m-p/1813487#M38337</link>
      <description>&lt;P&gt;HI&amp;nbsp;Anonymous&lt;/a&gt;.&amp;nbsp;Thanks. Yes, I created a date table, you can see my file above. I'm just stuck on the -7 days part.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically I need the number 7 days before the measure below. I'm unsure how to do that.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;CALCULATE (
    SUM( covidpercounty[ConfirmedCovidCases] ),
    FILTER ( 'Date', WEEKDAY ('Date'[Date] ) = 1 )
)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 29 Apr 2021 08:43:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-a-week-before-value/m-p/1813487#M38337</guid>
      <dc:creator>MargaretJames</dc:creator>
      <dc:date>2021-04-29T08:43:59Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating a week before value</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-a-week-before-value/m-p/1813974#M38352</link>
      <description>&lt;LI-CODE lang="csharp"&gt;[Sum Of Cases] = SUM( CovidPerCountry[ConfirmedCovidCases] )

[7Day Rolling Sum] =
var LastVisibleDate = MAX( 'Date'[Date] )
var _7DayPeriod =
    DATESINPERIOD(
        'Date'[Date],
        LastVisibleDate,
        -7,
        DAY
    )
var Result = 
    CALCULATE(
        [Sum Of Cases],
        _7DayPeriod,
        // If your 'Date' table is marked
        // as a date table in the model,
        // this last line is unnecessary.
        ALL( 'Date' )
    )
RETURN
    Result&lt;/LI-CODE&gt;&lt;P&gt;This works but when you're nearing the beginning of time in your 'Date' table, for the first 6 days you'll get a sum over the existing days, of which there will not be exactly 7. You can either ignore this or you can change the logic so that the result is calculated only if _7DayPeriod contains exactly 7 days.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 11:13:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-a-week-before-value/m-p/1813974#M38352</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-04-29T11:13:15Z</dc:date>
    </item>
  </channel>
</rss>

